Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

destroywindow and destroyallwindows not working.

Mac, Python 3.5.2

destroywindow and destroyallwindows cannot close the windows created by the program.

I found something saying I need to use waitkey afterwards but I can't get it to work.

The following code isn't mine it's from a tutorial as an example that should work. The code successfully displays the live feed from my webcam but the window won't close when I hit 'q' to escape.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Display the resulting frame
    cv2.imshow('frame',frame)


    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


cv2.destroyWindow('frame')

# When everything done, release the capture
cap.release()

##