Ask Your Question
0

destroywindow and destroyallwindows not working.

asked 2016-09-14 19:35:24 -0600

iskiskisk gravatar image

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()

##
edit retag flag offensive close merge delete

Comments

Hi @iskiskisk I have the same issue, did you manage to find a solution?

lucacerone gravatar imagelucacerone ( 2017-03-22 01:32:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-10-20 13:22:17 -0600

abhi_links gravatar image

write cv2.waitKey(1) after cv2.destroyWindows('frame') This worked for me.

edit flag offensive delete link more

Comments

thank you dear friend!

stiv-yakovenko gravatar imagestiv-yakovenko ( 2020-04-15 16:52:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-14 19:35:24 -0600

Seen: 16,791 times

Last updated: Sep 14 '16