0

Running the following code on my raspberry pi 4b with the camera v2 and OpenCV installed via pip install opencv-python I have no issues:

import cv2
cam = cv2.VideoCapture(0)
cam.isOpened() # True

However, when I installed OpenCV with the manual build described here, with the following variables:

export CMAKE_ARGS="-DENABLE_NEON=ON -DENABLE_VFPV3=ON -DWITH_GSTREAMER=ON"
export ENABLE_CONTRIB=1

Running the same code gives this error:

[ WARN:0] global /tmp/pip-req-build-4nusm4mm/opencv/modules/videoio/src/cap_gstreamer.cpp (1825) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Failed to allocate required memory.
[ WARN:0] global /tmp/pip-req-build-4nusm4mm/opencv/modules/videoio/src/cap_gstreamer.cpp (914) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global /tmp/pip-req-build-4nusm4mm/opencv/modules/videoio/src/cap_gstreamer.cpp (501) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0] global /tmp/pip-req-build-4nusm4mm/opencv/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

I believe I have all the required dependencies and gstreamer libs. I have tried multiple different things including changing /dev/video0 permissions and sudo modprobe bcm2835-v4l2 all to no avail.

OpenCV version 4.5.1, GStreamer version 1.14.4

1 Answer 1

1

I got the same problem when using raspberrypi camera the problem was that it outputs NV12 format not RGB you can use this code to test your camera https://github.com/JetsonHacksNano/CSI-Camera

or just add "format=(string)NV12" as a parameter of cv2.VideoCapture

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.