Not able to get frame from the second run (OpenCV on Rasbian)?
Hi everyone,
i have the following code to run on Rasbian (Raspberry Pi 3's OS):
import cv2
import threading
id = 0
cam = cv2.VideoCapture(id)
while True:
rt = cam.grab()
ret,frame = cam.retrieve(rt)
if ret:
cv2.imshow("Cam"+str(id),frame)
else:
# Addtional code
**while not cam.isOpened():
cam.release()
cam = cv2.VideoCapture(id)**
k = cv2.waitKey(1) & 0xFF
if k == ord('q'):
break
cam.release()
At the first run, nothing to say.
from the second run, x value is always false and i must reopen camera continuously.
Why is the ret variable false? Is there any other way? (Compare to my way - additional code)
Thank
you definitely should NOT close & reopen the capture.
also please check
cam.isOpened()
, before starting your loop.@berak: I have checked
cam.isOpened()
but this function always returns false. How can I pass it? If I change code to read 2 or more cameras, I can't get frame from cameras from the second run :(If I run the above code on Windows, no error occur
your raspi might have an install problem. (no idea about that, sorry)
you just won't change anything by hacking your python script.