DestroyWindow does not close window on Mac using Python and OpenCV

后端 未结 12 1093
野趣味
野趣味 2020-11-27 05:36

My program generates a series of windows using the following code:

def display(img, name, fun):
    global clicked

    cv.NamedWindow(name, 1)
    cv.ShowIm         


        
12条回答
  •  清酒与你
    2020-11-27 05:41

    You need to run cv.startWindowThread() after opening the window. I had the same issue and now this works for me.

    Hope this helps for future readers. And there is also a cv2 binding (I advise to use that instead of cv).

    This code works for me:

    import cv2 as cv
    import time
    
    WINDOW_NAME = "win"
    
    image = cv.imread("ela.jpg", cv.CV_LOAD_IMAGE_COLOR)
    cv.namedWindow(WINDOW_NAME, cv.CV_WINDOW_AUTOSIZE)
    initialtime = time.time()
    
    cv.startWindowThread()
    
    while (time.time() - initialtime < 5):
      print "in first while"
    cv.imshow(WINDOW_NAME, image)
    cv.waitKey(1000)
    
    cv.waitKey(1)
    cv.destroyAllWindows()
    cv.waitKey(1)
    
    initialtime = time.time()
    while (time.time() - initialtime < 6):
        print "in second while"
    

    The same issue happens with the C++ version, on Linux: Trying to close OpenCV window has no effect

提交回复
热议问题