Search code examples
pythonopencvraspberry-picamera

OpenCV USB-camera does not work on Raspberry Pi 4 32-bit


When I am trying to start videocapuring with opencv and python, it simply does not load. Does not show any problems, does not return anything. NOTHING!!!

The code is the simpliest one:

import cv2
import sys

video_capture = cv2.VideoCapture(0)

while True:
   ret, frame = video_capture.read()

   cv2.imshow('Video', frame)

   if cv2.waitKey(1) & 0xFF == ord('q'):
       break

video_capture.release()
cv2.destroyAllWindows()

This is the result of running this program

enter image description here

if I run code line by line, this is where it gets stuck

enter image description here

If I press Ctrl+C during execution of last line this is what it tells me:

Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.

You need to explicitly set elements to the NULL state before

dropping the final reference, to allow them to clean up.

This problem may also be caused by a refcounting bug in the

application or some element.

Solution

  • Maybe not really a solution, but a 0-effort thing to try is specify the video backend like this:

    video_capture = cv2.VideoCapture(0, CAP_V4L2)