-
Notifications
You must be signed in to change notification settings - Fork 236
Description
Raspberry Pi 5 and AI Camera
Describe the bug
When I set the camera to output BGR openCV shows wrong colours. When I tell the camera to use RGB openCV displays the colours correct. This suggests R and B are swapped.
Environment
Hardware: Raspberry Pi 5 + IMX500 (AI camera)
OS: Raspberry Pi OS Bookworm (64-bit)
rpicam-apps: v1.9.0 eca9928b76c1 (11-09-2025)
libcamera: v0.5.2+99-bfd68f78
libcamera libs in use (ldd):
libcamera.so.0.5 => /lib/aarch64-linux-gnu/libcamera.so.0.5
libcamera-base.so.0.5 => /lib/aarch64-linux-gnu/libcamera-base.so.0.5
Picamera2: 0.3.31-1 (apt package)
Pipeline: rpi/pisp (RP1)
Python
3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0]
/usr/lib/python3/dist-packages/picamera2/init.py
Name: picamera2
Version: 0.3.31
Summary: The libcamera-based Python interface to Raspberry Pi cameras, based on the original Picamera library
Home-page: https://github.com/RaspberryPi/picamera2
Author: Raspberry Pi & Raspberry Pi Foundation
Author-email: picamera2@raspberrypi.com
License: BSD 2-Clause License
Location: /usr/lib/python3/dist-packages
Requires: av, jsonschema, libarchive-c, numpy, PiDNG, piexif, pillow, python-prctl, simplejpeg, tqdm, videodev2
Required-by: #875
Example log:
(pi-ai-venv) andy@raspberrypi5:~/SSD/Andy-Ai-Cam $ rpicam-hello -t 1 2>&1 | sed -n '1,40p'
[9:25:21.442177707] [484048] INFO Camera camera_manager.cpp:330 libcamera v0.5.2+99-bfd68f78
[9:25:21.449630424] [484052] INFO RPI pisp.cpp:720 libpisp version v1.2.1 981977ff21f3 29-04-2025 (14:13:50)
[9:25:21.453535515] [484052] INFO IPAProxy ipa_proxy.cpp:180 Using tuning file /usr/share/libcamera/ipa/rpi/pisp/imx500.json
[9:25:21.461727217] [484052] INFO Camera camera_manager.cpp:220 Adding camera '/base/axi/pcie@1000120000/rp1/i2c@80000/imx500@1a' for pipeline handler rpi/pisp
[9:25:21.461757254] [484052] INFO RPI pisp.cpp:1179 Registered camera /base/axi/pcie@1000120000/rp1/i2c@80000/imx500@1a to CFE device /dev/media3 and ISP device /dev/media0 using PiSP variant BCM2712_D0
Made X/EGL preview window
Mode selection for 2028:1520:12:P
SRGGB10_CSI2P,2028x1520/0 - Score: 1000
SRGGB10_CSI2P,4056x3040/0 - Score: 1887
Stream configuration adjusted
[9:25:21.628612326] [484048] INFO Camera camera.cpp:1215 configuring streams: (0) 2028x1520-YUV420/sYCC (1) 2028x1520-RGGB_PISP_COMP1/RAW
[9:25:21.628813642] [484052] INFO RPI pisp.cpp:1483 Sensor: /base/axi/pcie@1000120000/rp1/i2c@80000/imx500@1a - Selected sensor format: 2028x1520-SRGGB10_1X10/RAW - Selected CFE format: 2028x1520-PC1R/RAW
To Reproduce
#!/usr/bin/env python3
import cv2
from picamera2 import Picamera2
IMG_W, IMG_H = 640, 480 # small for quick test
picam2 = Picamera2()
config = picam2.create_video_configuration(
main={"size": (IMG_W, IMG_H), "format": "RGB888"},
buffer_count=4
)
picam2.configure(config)
picam2.start()
frame = picam2.capture_array() # should be RGB, but may be swapped
picam2.stop()
r_mean = frame[...,0].mean()
g_mean = frame[...,1].mean()
b_mean = frame[...,2].mean()
print(f"Channel means (expect red >> others on a red target):")
print(f"R: {r_mean:.1f}, G: {g_mean:.1f}, B: {b_mean:.1f}")
cv2.imwrite("imx500_rgb888_test.png", frame)
print("Saved test frame to imx500_rgb888_test.png")
Expected behaviour
I expect openCV to display the wrong colours if I set the camera to RGB because openCV wants BGR
On a red target, R mean should be largest.
Actual
On a red target, B mean is largest.
Swapping channels fixes it.
Hardware :
Raspberry Pi 5 + AI Camera with IMX500
Additional context
Raspberry OS - new Pi and Camera bought recently.