Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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