Arducam IMX219 camera not working on Raspberry Pi 5 with OpenCV at 320x240

Hey everyone, I’m stuck trying to get my Arducam 4K 8MP IMX219 camera module working on a Raspberry Pi 5 with OpenCV. I’ve never been able to get a proper feed at 320x240 — the camera just won’t cooperate.

Here’s the code I’m running:

import cv2

cap = cv2.VideoCapture(0)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)

if not cap.isOpened():
    print("Error: Could not open camera.")
    exit()

while True:
    ret, frame = cap.read()
    if not ret:
        print("Error: Failed to capture frame.")
        break

    cv2.imshow('Camera', frame)

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

cap.release()
cv2.destroyAllWindows()

It either fails to open the camera entirely or I get “Failed to capture frame” in the loop. I’ve tried reinstalling OpenCV and checking the ribbon cable connection — everything seems fine physically. Any ideas what’s going on?

Thanks for posting the full code — that helps a lot. I actually have the same Arducam 4K 8MP IMX219 module here, so I ran your exact script on my test PC and it worked without any issues at 320x240.

That tells me the camera module itself and the code are fine. Could you try connecting the camera to a different PC (not the Pi 5) just to rule out whether the problem follows the camera or stays with that specific Raspberry Pi? That would help narrow things down significantly.

Unfortunately the Pi 5 is the only environment I have available for this project — I don’t have another PC I can test the camera on. Is there any other way to troubleshoot this on the Pi 5 itself? I’ve already checked the camera is detected via libcamera-hello --list-cameras and it shows up there, but OpenCV just doesn’t want to play nice with it.

Quick update — so I ended up borrowing a friend’s Raspberry Pi 5 and flashed the same SD card image onto it. Your exact code from my first post now works perfectly at 320x240. The camera feed comes through fine, no errors at all.

So it looks like the issue was specific to my original Pi 5 board. Same camera module, same SD card, same code — just a different Pi 5 unit. Strange.

Glad to hear you got it working, even if the root cause is a bit of a mystery. Given that the same camera module and SD card image work fine on a different Pi 5, the problem was almost certainly something environmental with your original board. Could be a marginal CSI connector, a slightly out-of-spec voltage rail, some GPIO interference, or even just a dirty/bent pin on the ribbon interface that only manifests under certain conditions.

Since the camera shows up in libcamera-hello but fails in OpenCV, it might also be worth checking if there’s a kernel or firmware version mismatch on the problematic board — you could compare uname -a and vcgencmd version between the two units if you’re curious.

For now though, the bottom line is: the Arducam IMX219 works fine on Raspberry Pi 5 at 320x240 with your code. The original board seems to be the culprit.