Skip to content

Problem with recent cv2 version on a RasPi Zero W: VIDEOIO(...): can't open camera by index #4

Description

@FabPi

hey,

thanks for your work, helped a lot. Anyway, i faced an error embedding this to my RasPi zero W and so i had to modify your code:
_
VIDEOIO(V4L2:/dev/video0): can't open camera by index
_

I fixed it by rewrite and include cv2.VideoCapture(0) into the video_stream() function:

def video_stream():
    video = cv2.VideoCapture(0)
    while True:
        ret, frame = video.read()
        if not ret:
            break;
        else:
            ret, buffer = cv2.imencode('.jpeg',frame)
            frame = buffer.tobytes()
            yield (b' --frame\r\n' b'Content-type: imgae/jpeg\r\n\r\n' + frame +b'\r\n')
    video.release()

after that, it workes as intended.

Best Regards
Fabian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions