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