-
Notifications
You must be signed in to change notification settings - Fork 0
Camera Setup
The Raspberry Pi camera, in this case a Raspberry Pi Camera V2 was set up using the Picamera2 library to capture frames in real-time.
The only library/configuration that I needed to make the camera to work on python in a fresh new Raspberry-pi OS (10/16/2024), with specs:
OS: Debian GNU/Linux 12 (bookworm) aarch64
Host: Raspberry Pi 4 Model B Rev 1.4
Kernel: 6.6.51+rpt-rpi-v8
was:
$ sudo apt install python3-picamzero
First, import Picamera2 class.
from picamera2 import Picamera2
It provides functions for controlling the camera, configuring settings, and retrieving image frames for processing.
Then initialize and configure the camera:
# Initialize Picamera2 and configure the camera
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
picam2.start()
Here, the key points are:
-
Resolution: The camera captures frames at
640x480
pixels. -
Format -
XRGB8888
:- This format is a 32-bit pixel format where each pixel consists of four 8-bit channels:
X
,R
,G
, andB
- total of 4 bytes (32 bits).
- This format is a 32-bit pixel format where each pixel consists of four 8-bit channels:
Although the X
channel is ignored, having it simplifies alignment (padding) and access to color channels, making XRGB8888
efficient for processing tasks.
To Capture Frames it is simple as:
frame = picam2.capture_array()
Here, frames are captured as NumPy arrays, each containing the pixel data in the XRGB8888
format.
Finnaly, at the end of the program, we use:
picam2.stop()
to halt the camera stream. Stopping the stream ensures that resources are released and allows the system to be used for other tasks without interference.