Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python freezes after cv2.destroyWindow()

I am using openCV under Python 2.7 on Mac OS X (Lion)...Whenever I run code to simply display a camera feed (from iSight) Python freezes. It looks like the camera is not actually getting cleaned up. I have used a number of different versions of the same code (below, which is from a different question on SO) and get the same results (whether in cv or cv2). Anyone have any idea why this is happening? Here is the code:

import cv2

cv2.namedWindow("camera",1)
capture = cv2.VideoCapture()
capture.open(0)
while True:
    img = capture.read()[1]
    cv2.imshow("camera", img)
    if cv2.waitKey(10) == 27: break
cv2.destroyWindow("camera")
like image 384
caseyanderson Avatar asked Dec 05 '12 23:12

caseyanderson


People also ask

What does cv2 destroyAllWindows () do?

0 – wait indefinitely cv2. destroyAllWindows() simply destroys all the windows we created. To destroy any specific window, use the function cv2. destroyWindow() where you pass the exact window name.

What is difference between OpenCV and cv2?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

How do I close an image after cv2 Imshow?

destroyAllWindows(). Inside the cv2. waitKey() function, you can provide any value to close the image and continue with further lines of code.

What is CV waitKey?

Python OpenCV – waitKey() Function waitkey() function of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed.


1 Answers

This is a problem with all *nux based system. Please check out this question and the answer from other question on StackOverflow.

DestroyWindow does not close window on Mac using Python and OpenCV

In short, it seems that you will need to call waitKey() for the message pump in OpenCV.

like image 122
user1899365 Avatar answered Nov 04 '22 05:11

user1899365