OpenCV window always on top

后端 未结 3 1480
我寻月下人不归
我寻月下人不归 2020-12-06 21:31

Is there a way to set a OpenCV window to be always on top? And can i remove the minimize and close button from my window? Thank you.

相关标签:
3条回答
  • 2020-12-06 21:35

    I found the best solution posted in comments here: Python OpenCV open window on top of other applications

    Simply add the command below after opening a window, e.g.

    cv2.namedWindow('img_file_name', cv2.WINDOW_NORMAL) # Creates a window
    os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "python" to true' ''') # To make window active
    

    Use "python" in lower case. Using "Python", as I found in some answers, gave me an error:

    21:62: execution error: Finder got an error: Can’t set process "Python" to true. (-10006))
    
    0 讨论(0)
  • 2020-12-06 21:38

    You can use: cvGetWindowHandle() to obtain Widows handler. Then using regular windows API you can do anything you like

    0 讨论(0)
  • 2020-12-06 21:57

    I found that all I needed to do was set my main window to fullscreen then back to normal.

        #!/usr/bin/env python
        import cv2
        import numpy
    
        WindowName="Main View"
        view_window = cv2.namedWindow(WindowName,cv2.WINDOW_NORMAL)
    
        # These two lines will force your "Main View" window to be on top with focus.
        cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
        cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_NORMAL)
    
        # The rest of this does not matter. This would be the rest of your program.
        # This just shows an image so that you can see that this example works.
        img = numpy.zeros((400,400,3), numpy.uint8)
        for x in range(0,401,100):
            for y in range(0,401,100):
                cv2.line(img,(x,0),(0,y),(128,128,254),1)
                cv2.line(img,(x,399),(0,y),(254,128,128),1)
                cv2.line(img,(399,y),(x,399),(128,254,128),1)
                cv2.line(img,(399,y),(x,0),(254,254,254),1)
        cv2.imshow(WindowName, img)
        cv2.waitKey(0)
        cv2.destroyWindow(WindowName)
    
    0 讨论(0)
提交回复
热议问题