Rpi5 camera doesn't work

I want to use my raspberry pi 5 for pose estimation.

The past week I have been using my rpi4 with a webcam and the pose estimation as worked pretty well. However, I wanted to migrate to the rpi5 for better compute power, and I want to move towards a built in camera because it is less clunky…

After I set up my rpi5 with the camera and opencv + mediapipe I ran the code provided below. I receive no errors but the camera feed does not open :confused:

when I use the rpicam-still command my camera opens just fine! please help :upside_down_face:

import cv2
import mediapipe as mp

# Initialize MediaPipe Pose model
mp_pose = mp.solutions.pose
pose = mp_pose.Pose()

# Initialize Raspberry Pi camera
cap = cv2.VideoCapture(0)  # 0 for the first camera, 1 for the second, and so on

while cap.isOpened():
    # Read frame from the camera
    ret, frame = cap.read()
    if not ret:
        break

    # Convert the image to RGB
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # Perform pose estimation
    results = pose.process(frame_rgb)

    # Draw the detected poses
    if results.pose_landmarks:
        mp_drawing = mp.solutions.drawing_utils
        mp_drawing.draw_landmarks(frame, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)

    # Display the frame with detected poses
    cv2.imshow('Pose Estimation', frame)

    # Check for exit key
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release resources
cap.release()
cv2.destroyAllWindows()

my original post: https://forums.raspberrypi.com/viewtopic.php?t=369106
camera im using: https://www.amazon.co.uk/gp/product/B00N1YJKFS/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

Of course, the problem that you neef help for, has nothing to do with pose estimation - just with that device configuration
#postingTitles

I really wish those raspberry pi people would google a little before asking the same questions every day without pause.

OpenCV supports V4L/V4L2. That is the standard for video devices on Linux.

“Pi cameras” refuse to support this. That is Raspberry Pi’s problem, not OpenCV’s problem.

That is all. Please take this back to the rpi forum.

1 Like

I’m seeing the same issue. Dare I say what the subject matter is, but the conclusion is the same for me, on pi5 bookworm: cv2 with USB camera works. cv2 with ribbon cabled Rpi Camera Module 3 fails on capture.read() without any detail as to why it failed to read.

rpicam-video works fine with ribbon cam, but I suspect that is not using open cv and instead talking directly to mediapipe.

Here is a dump of v4l info with the ribbon cable cam installed in case anyone at opencv is working the issue. Thank you for this awesome package, -bee

(base) bee@pi5:~ $ sudo apt install v4l-utils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
v4l-utils is already the newest version (1.22.1-5+b2).
The following package was automatically installed and is no longer required:
  libwlroots12
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.


(base) bee@pi5:~ $  v4l2-ctl --all -d /dev/video0
Driver Info:
	Driver name      : rp1-cfe
	Card type        : rp1-cfe
	Bus info         : platform:1f00110000.csi
	Driver version   : 6.6.62
	Capabilities     : 0xaca00001
		Video Capture
		Metadata Capture
		Metadata Output
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps      : 0x24a00001
		Video Capture
		Metadata Capture
		Streaming
		Extended Pix Format
Media Driver Info:
	Driver name      : rp1-cfe
	Model            : rp1-cfe
	Serial           :
	Bus info         : platform:1f00110000.csi
	Media version    : 6.6.62
	Hardware revision: 0x00114666 (1132134)
	Driver version   : 6.6.62
Interface Info:
	ID               : 0x03000017
	Type             : V4L Video
Entity Info:
	ID               : 0x00000015 (21)
	Name             : rp1-cfe-csi2_ch0
	Function         : V4L2 I/O
	Pad 0x01000016   : 0: Sink, Must Connect
	  Link 0x02000037: from remote pad 0x1000006 of entity 'csi2' (Video Interface Bridge): Data
Priority: 2
Video input : 0 (rp1-cfe-csi2_ch0: ok)
Format Video Capture:
	Width/Height      : 640/480
	Pixel Format      : 'pRAA' (10-bit Bayer RGRG/GBGB Packed)
	Field             : None
	Bytes per Line    : 800
	Size Image        : 384000
	Colorspace        : Raw
	Transfer Function : None
	YCbCr/HSV Encoding: ITU-R 601
	Quantization      : Full Range
	Flags             :
Format Metadata Capture:
	Sample Format   : 'SENS' (Sensor Ancillary Metadata)
	Buffer Size     : 16384

Also, outside the scope of this problem. I would really love to know why the moderator feels it is necessary to attack a whole group via one who took the time to report a bug in a package, for me at least, has been one of the biggest PITA to install on anything other than a very specific set of hardware for a very long time.

BTW, according to this opencv-issue: Raspberry Pi 5+Module 3 camera can not read frame with openv · Issue #25072 · opencv/opencv · GitHub this is an issue with open cv that they don’t plan on fixing. I think that is what you meant to say.

The correct solution for anyone who stumbles on this thread: capture the image using something other than cv2 and then feed that through cv2.

Or maybe you’d prefer to say goodbye to cv2 all together and just do what you needed open-cv to do using mediapipe directly: Object Detection and Tracking using MediaPipe - Google Developers Blog

that is not the case. mediapipe has nothing to do with media or piping, nor with accessing camera devices. it’s an AI inference framework.

as a group, raspberry pi users stand out in that they are a lot, and a lot of them don’t seem capable of finding answers by using web search. that’s why a lot of them keep showing up everywhere, asking the same questions that they expect the same answers to, that have been asked and answered countless times before.

would you, as a person, feel it tedious to be asked the same questions over and over?

I guess, representing rpi people, you’d rather receive no response at all to repeated questions. since that seems to be what you’re asking for, I think that’ll be my policy from now on.

Oh, I’m sorry the job of moderator is a difficult one and I wouldn’t want it.

Most people are incapable of finding answers on the Internet now. In part, it’s exactly because of threads like this one where someone experiencing the same problem hopes to find a clue to a solution and instead gets vitriol.

Something tells me you have many opinions about many groups of people.

Regarding using mediapipe - I misspoke.

If you want to use the ribbon cable Pi camera on Pi5, you need to use something other than cv2. Bookworm installs Python 3.11 and picamera2 and although their user manual make’s it look daunting, picamera2 is pretty easy to use

# see, https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf
from picamera2 import Picamera2  # type: ignore

camera = Picamera2()
camera.start()
image = capture_array()
# do whatever with image; pass to opencv, tflite, mediapipe....

Make sure you include system packages when you create your Python venv:

python -m venv --system-site-packages base