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")
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.
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.
destroyAllWindows(). Inside the cv2. waitKey() function, you can provide any value to close the image and continue with further lines of code.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With