當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.getWindowProperty方法代碼示例

本文整理匯總了Python中cv2.getWindowProperty方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.getWindowProperty方法的具體用法?Python cv2.getWindowProperty怎麽用?Python cv2.getWindowProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.getWindowProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: show

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def show(window, img):
    """
    Shows the image in OpenCV window with support for updating
    the image in real-time. This will simply repeatedly display the image.
    This makes real-time update of image possible and also lets us handle
    window close events reliably.

    Params:
    window: A python string, the name of the window in which to show the image
    img: A numpy array. Image to be shown.
    """
    while(1):  # Will repeatedly show the image in given window.
        cv2.imshow(window, img)
        k = cv2.waitKey(1) & 0xFF  # Capture the code of the pressed key.
        # Stop the loop when the user clicks on GUI close button [x].
        if not cv2.getWindowProperty(window, cv2.WND_PROP_VISIBLE):
            print("Operation Cancelled")
            break
        if k == 27:  # Key code for ESC
            break 
開發者ID:HoussemCharf,項目名稱:FunUtils,代碼行數:22,代碼來源:facesearch.py

示例2: run

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def run(self):
        while cv2.getWindowProperty('img', 0) != -1 or cv2.getWindowProperty('watershed', 0) != -1:
            ch = cv2.waitKey(50)
            if ch == 27:
                break
            if ch >= ord('1') and ch <= ord('7'):
                self.cur_marker = ch - ord('0')
                print('marker: ', self.cur_marker)
            if ch == ord(' ') or (self.sketch.dirty and self.auto_update):
                self.watershed()
                self.sketch.dirty = False
            if ch in [ord('a'), ord('A')]:
                self.auto_update = not self.auto_update
                print('auto_update if', ['off', 'on'][self.auto_update])
            if ch in [ord('r'), ord('R')]:
                self.markers[:] = 0
                self.markers_vis[:] = self.img
                self.sketch.show()
        cv2.destroyAllWindows() 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:21,代碼來源:watershed.py

示例3: imshow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def imshow(img, win_name='', wait_time=0):
    """Show an image.

    Args:
        img (str or ndarray): The image to be displayed.
        win_name (str): The window name.
        wait_time (int): Value of waitKey param.
    """
    cv2.imshow(win_name, imread(img))
    if wait_time == 0:  # prevent from hangning if windows was closed
        while True:
            ret = cv2.waitKey(1)

            closed = cv2.getWindowProperty(win_name, cv2.WND_PROP_VISIBLE) < 1
            # if user closed window or if some key pressed
            if closed or ret != -1:
                break
    else:
        ret = cv2.waitKey(wait_time) 
開發者ID:open-mmlab,項目名稱:mmcv,代碼行數:21,代碼來源:image.py

示例4: is_window_closed

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def is_window_closed(self):
        """Try to determine if the user closed the window (by clicking the x).

        This may only work with OpenCV 3.x.

        All OpenCV window properties should return -1.0 for windows that are closed.
        If we read a property that has a value < 0 or an exception is raised we assume
        the window has been closed. We use the aspect ratio property but it could be any.

        """
        try:
            prop_asp = cv2.getWindowProperty(self._window_name, cv2.WND_PROP_ASPECT_RATIO)
            if prop_asp < 0.0:
                # the property returned was < 0 so assume window was closed by user
                return True
        except:
            return True

        return False 
開發者ID:movidius,項目名稱:ncappzoo,代碼行數:21,代碼來源:mnist_calc.py

示例5: display_prediction

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def display_prediction(frame, frameString, fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                       fontScale=1, thickness=2):

    # Display emotion
    retval, _ = cv2.getTextSize(
        frameString, fontFace, fontScale, thickness)
    cv2.rectangle(frame, (0, 0), (20 + retval[0], 50), (0, 0, 0), -1)
    cv2.putText(frame, frameString, (10, 35), fontFace, fontScale,
                (255, 255, 255), thickness, cv2.LINE_AA)

    window_name = 'EmoPy Assessment'
    cv2.imshow(window_name, frame)

    while True:

        key = cv2.waitKey(1)
        # Press Esc to exit the window
        if key == 27 or cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1:
            break

    # Closes all windows
    cv2.destroyAllWindows() 
開發者ID:thoughtworksarts,項目名稱:EmoPy,代碼行數:24,代碼來源:fermodel_example_webcam.py

示例6: show_camera

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def show_camera():
    # To flip the image, modify the flip_method parameter (0 and 2 are the most common)
    print(gstreamer_pipeline(flip_method=0))
    cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
    if cap.isOpened():
        window_handle = cv2.namedWindow('CSI Camera', cv2.WINDOW_AUTOSIZE)
        # Window 
        while cv2.getWindowProperty('CSI Camera',0) >= 0:
            ret_val, img = cap.read();
            cv2.imshow('CSI Camera',img)
	    # This also acts as 
            keyCode = cv2.waitKey(30) & 0xff
            # Stop the program on the ESC key
            if keyCode == 27:
               break
        cap.release()
        cv2.destroyAllWindows()
    else:
        print('Unable to open camera') 
開發者ID:joakimeriksson,項目名稱:ai-smarthome,代碼行數:21,代碼來源:simple-camera.py

示例7: is_running

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def is_running(self):
        return (cv2.waitKey(1) != 27) and (cv2.getWindowProperty(self._window_name, cv2.WND_PROP_VISIBLE) >= 1) 
開發者ID:siqueira-hc,項目名稱:Efficient-Facial-Feature-Learning-with-Wide-Ensemble-based-Convolutional-Neural-Networks,代碼行數:4,代碼來源:fer_demo.py

示例8: map

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def map(self, data):
        image = data[self.src]

        cv2.imshow(self.window_name, image)

        # Exit?
        key = cv2.waitKey(1) & 0xFF
        # Esc key pressed or window closed?
        if key == 27 or cv2.getWindowProperty(self.window_name, cv2.WND_PROP_VISIBLE) < 1:
            raise StopIteration

        return data 
開發者ID:jagin,項目名稱:detectron2-pipeline,代碼行數:14,代碼來源:display_video.py

示例9: loop_and_display

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_display(condition, vis):
    """Take detection results from the child thread and display.

    # Arguments
        condition: the condition variable for synchronization with
                   the child thread.
        vis: for visualization.
    """
    global s_img, s_boxes, s_confs, s_clss

    full_scrn = False
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            break
        with condition:
            # Wait for the next frame and detection result.  When
            # getting the signal from the child thread, save the
            # references to the frame and detection result for
            # display.
            condition.wait()
            img, boxes, confs, clss = s_img, s_boxes, s_confs, s_clss
        img = vis.draw_bboxes(img, boxes, confs, clss)
        img = show_fps(img, fps)
        cv2.imshow(WINDOW_NAME, img)
        toc = time.time()
        curr_fps = 1.0 / (toc - tic)
        # calculate an exponentially decaying average of fps number
        fps = curr_fps if fps == 0.0 else (fps*0.95 + curr_fps*0.05)
        tic = toc
        key = cv2.waitKey(1)
        if key == 27:  # ESC key: quit program
            break
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_display(WINDOW_NAME, full_scrn) 
開發者ID:jkjung-avt,項目名稱:tensorrt_demos,代碼行數:39,代碼來源:trt_ssd_async.py

示例10: loop_and_detect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_detect(cam, trt_yolov3, conf_th, vis):
    """Continuously capture images from camera and do object detection.

    # Arguments
      cam: the camera instance (video source).
      trt_yolov3: the TRT YOLOv3 object detector instance.
      conf_th: confidence/score threshold for object detection.
      vis: for visualization.
    """
    full_scrn = False
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            break
        img = cam.read()
        if img is not None:
            boxes, confs, clss = trt_yolov3.detect(img, conf_th)
            img = vis.draw_bboxes(img, boxes, confs, clss)
            img = show_fps(img, fps)
            cv2.imshow(WINDOW_NAME, img)
            toc = time.time()
            curr_fps = 1.0 / (toc - tic)
            # calculate an exponentially decaying average of fps number
            fps = curr_fps if fps == 0.0 else (fps*0.95 + curr_fps*0.05)
            tic = toc
        key = cv2.waitKey(1)
        if key == 27:  # ESC key: quit program
            break
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_display(WINDOW_NAME, full_scrn) 
開發者ID:jkjung-avt,項目名稱:tensorrt_demos,代碼行數:34,代碼來源:trt_yolov3.py

示例11: loop_and_display

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_display(condition):
    """Continuously capture images from camera and do classification."""
    global s_img, s_probs, s_labels

    full_scrn = False
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            break
        with condition:
            condition.wait()
            img, top_probs, top_labels = s_img, s_probs, s_labels
        show_top_preds(img, top_probs, top_labels)
        img = show_fps(img, fps)
        cv2.imshow(WINDOW_NAME, img)
        toc = time.time()
        curr_fps = 1.0 / (toc - tic)
        # calculate an exponentially decaying average of fps number
        fps = curr_fps if fps == 0.0 else (fps*0.95 + curr_fps*0.05)
        tic = toc
        key = cv2.waitKey(1)
        if key == 27:  # ESC key: quit program
            break
        elif key == ord('H') or key == ord('h'):  # Toggle help message
            show_help = not show_help
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_display(WINDOW_NAME, full_scrn) 
開發者ID:jkjung-avt,項目名稱:tensorrt_demos,代碼行數:31,代碼來源:trt_googlenet_async.py

示例12: loop_and_detect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_detect(cam, trt_ssd, conf_th, vis):
    """Continuously capture images from camera and do object detection.

    # Arguments
      cam: the camera instance (video source).
      trt_ssd: the TRT SSD object detector instance.
      conf_th: confidence/score threshold for object detection.
      vis: for visualization.
    """
    full_scrn = False
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            break
        img = cam.read()
        if img is not None:
            boxes, confs, clss = trt_ssd.detect(img, conf_th)
            img = vis.draw_bboxes(img, boxes, confs, clss)
            img = show_fps(img, fps)
            cv2.imshow(WINDOW_NAME, img)
            toc = time.time()
            curr_fps = 1.0 / (toc - tic)
            # calculate an exponentially decaying average of fps number
            fps = curr_fps if fps == 0.0 else (fps*0.95 + curr_fps*0.05)
            tic = toc
        key = cv2.waitKey(1)
        if key == 27:  # ESC key: quit program
            break
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_display(WINDOW_NAME, full_scrn) 
開發者ID:jkjung-avt,項目名稱:tensorrt_demos,代碼行數:34,代碼來源:trt_ssd.py

示例13: loop_and_detect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_detect(cam, mtcnn, minsize):
    """Continuously capture images from camera and do face detection."""
    full_scrn = False
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            break
        img = cam.read()
        if img is not None:
            dets, landmarks = mtcnn.detect(img, minsize=minsize)
            print('{} face(s) found'.format(len(dets)))
            img = show_faces(img, dets, landmarks)
            img = show_fps(img, fps)
            cv2.imshow(WINDOW_NAME, img)
            toc = time.time()
            curr_fps = 1.0 / (toc - tic)
            # calculate an exponentially decaying average of fps number
            fps = curr_fps if fps == 0.0 else (fps*0.95 + curr_fps*0.05)
            tic = toc
        key = cv2.waitKey(1)
        if key == 27:  # ESC key: quit program
            break
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_display(WINDOW_NAME, full_scrn) 
開發者ID:jkjung-avt,項目名稱:tensorrt_demos,代碼行數:28,代碼來源:trt_mtcnn.py

示例14: loop_and_detect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def loop_and_detect(stream_handler, tf_sess, conf_th, vis, od_type):
    """Loop, grab images from camera, and do object detection.

    # Arguments
      stream_handler: the stream handler object.
      tf_sess: TensorFlow/TensorRT session to run SSD object detection.
      conf_th: confidence/score threshold for object detection.
      vis: for visualization.
    """
    show_fps = True
    full_scrn = True
    fps = 0.0
    tic = time.time()
    while True:
        if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
            # Check to see if the user has closed the display window.
            # If yes, terminate the while loop.
            break

        img = stream_handler.read_streams()
        box, conf, cls = detect(img, tf_sess, conf_th, od_type=od_type)
        cls-=1
        img = vis.draw_bboxes(img, box, conf, cls)
        if show_fps:
            img = draw_help_and_fps(img, fps)
        cv2.imshow(WINDOW_NAME, img)
        toc = time.time()
        curr_fps = 1.0 / (toc - tic)
        # calculate an exponentially decaying average of fps number
        fps = curr_fps if fps == 0.0 else (fps*0.9 + curr_fps*0.1)
        tic = toc

        key = cv2.waitKey(1)
        if key == ord('q') or key == ord('Q'):  # q key: quit program
            break
        elif key == ord('H') or key == ord('h'):  # Toggle help/fps
            show_fps = not show_fps
        elif key == ord('F') or key == ord('f'):  # Toggle fullscreen
            full_scrn = not full_scrn
            set_full_screen(full_scrn) 
開發者ID:dataplayer12,項目名稱:homesecurity,代碼行數:42,代碼來源:tx2_surveillance.py

示例15: window_closed

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import getWindowProperty [as 別名]
def window_closed(self, is_windows, is_conda, key):
        """ Check whether the window has been closed

        MS Windows doesn't appear to read the window state property
        properly, so we check for a negative key press.

        Conda (tested on Windows) doesn't appear to read the window
        state property or negative key press properly, so we arbitrarily
        use another property """
        # pylint: disable=no-member
        logger.trace("Commencing closed window check")
        closed = False
        prop_autosize = cv2.getWindowProperty('Frame', cv2.WND_PROP_AUTOSIZE)
        prop_visible = cv2.getWindowProperty('Frame', cv2.WND_PROP_VISIBLE)
        if self.arguments.disable_monitor:
            closed = False
        elif is_conda and prop_autosize < 1:
            closed = True
        elif is_windows and not is_conda and key == -1:
            closed = True
        elif not is_windows and not is_conda and prop_visible < 1:
            closed = True
        logger.trace("Completed closed window check. Closed is %s", closed)
        if closed:
            logger.debug("Window closed detected")
        return closed 
開發者ID:deepfakes,項目名稱:faceswap,代碼行數:28,代碼來源:jobs_manual.py


注:本文中的cv2.getWindowProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。