Python cv2.WND_PROP_VISIBLE Examples

The following are 8 code examples of cv2.WND_PROP_VISIBLE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: facesearch.py    From FunUtils with MIT License 7 votes vote down vote up
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 
Example #2
Source File: image.py    From mmcv with Apache License 2.0 6 votes vote down vote up
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) 
Example #3
Source File: fermodel_example_webcam.py    From EmoPy with GNU Affero General Public License v3.0 6 votes vote down vote up
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() 
Example #4
Source File: fer_demo.py    From Efficient-Facial-Feature-Learning-with-Wide-Ensemble-based-Convolutional-Neural-Networks with MIT License 5 votes vote down vote up
def is_running(self):
        return (cv2.waitKey(1) != 27) and (cv2.getWindowProperty(self._window_name, cv2.WND_PROP_VISIBLE) >= 1) 
Example #5
Source File: display_video.py    From detectron2-pipeline with MIT License 5 votes vote down vote up
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 
Example #6
Source File: jobs_manual.py    From faceswap with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #7
Source File: utils.py    From hermit with Apache License 2.0 5 votes vote down vote up
def window_is_open(window_name):
    return (cv2.waitKey(1) and
            cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) == 1.0) 
Example #8
Source File: display_video.py    From image-processing-pipeline with MIT License 5 votes vote down vote up
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