예제 #1
0
def Lyrebird():

    global Capturing

    ### Noticed DPI scaling is off at times on Windows
    ### If it still doesn't work correctly, right click python.exe in Explorer
    ### and set DPI compatibility as workaround under Compatibility settings
    if platform == "win32":
        ctypes.windll.shcore.SetProcessDpiAwareness(2)

    ### Take a screenshot and convert it so opencv can process it
    screenshot_temp = ImageGrab.grab()
    screenshot = np.array(screenshot_temp)
    screenshot = cv2.cvtColor(screenshot, cv2.COLOR_BGR2RGB)

    ### create a new fullscreen window and load the screenshot
    WindowName = "Lyrebird"
    cv2.namedWindow(WindowName, cv2.WINDOW_NORMAL)
    cv2.setWindowProperty(WindowName, cv2.WND_PROP_FULLSCREEN,
                          cv2.WINDOW_FULLSCREEN)
    cv2.imshow(WindowName, screenshot)

    Capturing = True

    ### Goal is to take a picture when mouse or keyboard is clicked
    cv2.setMouseCallback(WindowName, mouseAction)

    while Capturing:
        if (cv2.waitKey(1) & 0xFF) == 27:
            webcamCapture()
            break

    cv2.destroyAllWindows()
예제 #2
0
 def set_unset_full_screen(self):
     if not self.fullScreen:
         cv2.setWindowProperty(self.presentationName,
                               cv2.WND_PROP_FULLSCREEN,
                               cv2.WINDOW_FULLSCREEN)
         self.fullScreen = True
     else:
         cv2.setWindowProperty(self.presentationName,
                               cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL)
         self.fullScreen = False
                except Full:  # when the queue is full, ignore it
                    continue  # next loop


if __name__ == "__main__":
    """ mirror the image of the Viewport onto the Porthole """
    try:
        # opencv-python
        import cv2.cv2 as cv
    except ImportError:
        import cv2 as cv

    # create the Viewport window
    viewport = 'Viewport'
    cv.namedWindow(viewport, cv.WINDOW_GUI_NORMAL)
    cv.setWindowProperty(viewport, cv.WND_PROP_AUTOSIZE, cv.WINDOW_NORMAL)
    cv.setWindowProperty(viewport, cv.WND_PROP_ASPECT_RATIO,
                         cv.WINDOW_FREERATIO)

    set_start_method('spawn')  # windows default

    img_queue = Queue(maxsize=3)  # always up to date with a buffer of 3 frames
    # shared memory array with 4 places (left, upper, right, lower)
    monitor = Array('i', (1, 1, 2, 2))

    # start making screenshots
    screen_capture = ScreenCapture(img_queue, monitor)
    screen_capture.start()

    # use mss to get the width and height of the monitor(s)
    mon: dict = mss.mss().monitors[0]
예제 #4
0
                   lineType=8,
                   shift=0)
        contador_circulo_click -= 1

    #Este for es para mostrar los nombres, lo reemplazo con los cuadritos.

    cv2.imshow('Video', frame)

    #Funcion para guardar la cara con un click
    cv2.setMouseCallback('Video', save_face_click)

    cv2.imshow('Video', frame)

    #estas 2 lineas son para sacar la barra de la imagen
    cv2.namedWindow('Video', cv2.WINDOW_NORMAL)
    cv2.setWindowProperty('Video', cv2.WND_PROP_FULLSCREEN,
                          cv2.WINDOW_FULLSCREEN)

    cv2.moveWindow('Video', -35, -20)
    datos_ventana_video = cv2.getWindowImageRect(
        'Video')  #This will return a tuple of (x, y, w, h)

    #Esto es la grilla con fondo negro y datos
    cv2.imshow('grilla', grilla)

    #estas 2 lineas son para sacar la barra de la imagen
    cv2.namedWindow('grilla', cv2.WINDOW_NORMAL)
    cv2.setWindowProperty('grilla', cv2.WND_PROP_FULLSCREEN,
                          cv2.WINDOW_FULLSCREEN)

    #linea para mover la ventana y acomodarlas en la pantalla
    cv2.moveWindow('grilla', datos_ventana_video[0] + datos_ventana_video[2],
def main():
    button_pin = 7
    GPIO.setmode(GPIO.BCM)
    # load our serialized model from disk
    print("[INFO] loading model...")
    net = cv2.dnn.readNetFromCaffe(prototxt, model)

    # initialize the video stream, allow the cammera sensor to warmup,
    # and initialize the FPS counter
    print("[INFO] starting video stream...")
    vs = VideoStream(src=0).start()
    fps = FPS().start()

    ultrasonic = UltrasonicSystem({1: [8, 25], 2: [24, 23], 3: [15, 14]}, 3)
    ultrasonic.add_sensors()
    ultrasonic_spawn = threading.Thread(target=ultrasonic.spawn_sensor_threads,
                                        daemon=True)
    ultrasonic_spawn.start()
    GPIO.add_event_detect(button_pin, GPIO.RISING)
    try:
        # loop over the frames from the video stream
        while True:
            # grab the frame from the threaded video stream and resize it
            # to have a maximum width of 500 pixels
            frame = vs.read()
            frame = cv2.flip(frame, 1)
            # grab the frame dimensions and convert it to a blob
            (h, w) = frame.shape[:2]
            blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)),
                                         0.007843, (300, 300), 127.5)

            # pass the blob through the network and obtain the detections and
            # predictions
            net.setInput(blob)
            detections = net.forward()

            # loop over the detections
            for i in np.arange(0, detections.shape[2]):
                # extract the confidence (i.e., probability) associated with
                # the prediction
                confidence = detections[0, 0, i, 2]

                # filter out weak detections by ensuring the `confidence` is
                # greater than the minimum confidence
                if confidence > confidence_threshold:
                    # extract the index of the class label from the
                    # `detections`, then compute the (x, y)-coordinates of
                    # the bounding box for the object
                    idx = int(detections[0, 0, i, 1])
                    box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
                    (startX, startY, endX, endY) = box.astype("int")

                    # draw the prediction on the frame
                    label = "{}: {:.2f}%".format(CLASSES[idx],
                                                 confidence * 100)
                    cv2.rectangle(frame, (startX, startY), (endX, endY),
                                  COLORS[idx], 2)
                    y = startY - 15 if startY - 15 > 15 else startY + 15
                    cv2.putText(frame, label, (startX, y),
                                cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2)
            frame = ultrasonic.write_measurements_to_frame(frame)
            # show the output frame
            cv2.namedWindow("Frame", cv2.WND_PROP_FULLSCREEN)
            cv2.setWindowProperty("Frame", cv2.WND_PROP_FULLSCREEN,
                                  cv2.WINDOW_FULLSCREEN)
            # cv2.resizeWindow("Frame", 640, 480)
            cv2.imshow("Frame", frame)
            key = cv2.waitKey(1) & 0xFF

            if GPIO.event_detected(button_pin):
                ultrasonic.stop = True
                time.sleep(1)
                break

            # update the FPS counter
            fps.update()
        cleanup(fps, vs)
    except KeyboardInterrupt:
        cleanup(fps, vs)