Skip to content

Raspberry Pi Camera

The Raspberry Pi Camera Module v2 (IMX219) captures 8MP stills and 1080p30 video.

Enable Camera

bash
sudo raspi-config
# Interface Options → Camera → Enable
sudo reboot

Test

bash
libcamera-still -o test.jpg
libcamera-vid -t 5000 -o test.h264

Python with Picamera2

bash
pip install picamera2
python
from picamera2 import Picamera2
import cv2

picam = Picamera2()
picam.configure(picam.create_preview_configuration(
    main={"size": (640, 480), "format": "RGB888"}))
picam.start()

while True:
    frame = picam.capture_array()
    cv2.imshow("Pi Camera", frame)
    if cv2.waitKey(1) == ord('q'):
        break

ROS 2 Integration

bash
sudo apt install ros-humble-v4l2-camera
ros2 run v4l2_camera v4l2_camera_node --ros-args -p video_device:=/dev/video0

TIP

For better performance in ROS 2, use image_transport with compressed transport to reduce bandwidth on the network.

Released under the MIT License.