DestroyWindow does not close window on Mac using Python and OpenCV

后端 未结 12 1118
野趣味
野趣味 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:46

    I had the same issue. The problem is that while(cap.isOpened()): loop does not finish so that I added below structure. When video has no frame in the following part, it returns ret values as False. Normally, I put destroyAllWindows command out of loop but I moved it into the loop. It works in my code properly.

    while(cap.isOpened()):
     ret, frame = cap.read()  
     if ret == False:
            cap.release()
            cv2.waitKey(1)
            cv2.destroyAllWindows()
            cv2.waitKey(1)
    

提交回复
热议问题