Raspberry pi 4 : Raspi camera module 3 on Raspbian (Bookworm)

Posted

OS image

Raspi OS - Debian GNU/LINUX (Raspbian - bookworm)
Linux raspberry pi 6.12.25+rpi-v8 Debian aarch64

Setup Camera

config.txt
{
camera-auto-detect=0
dtoverlay=imx708
}
sudo apt update && sudo apt upgrade -y
sudo apt install [libcamera-dev libcamera-tools] wireplumber pipewire rpicam-apps libv4l-dev v4l-utils ffmpeg [raspi-config]
sudo raspi-config    
{
  Interface -> Legacy camera -> Enable #for Ubuntu only
  Interface -> SPI -> Enable
  Interface -> I2C -> Enable
}
sudo reboot now

Testing

cam -l
ls -lah /dev/video*
v4l2-ctl --list-devices
v4l2-ctl --list-formats
rpicam-vid -t 10s -o ./test.h264
ffmpeg -i test.h264 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 4 test.ogv
while true; do rpicam-vid --nopreview -t 1s --width  640 --height 480 -o - | ffmpeg -y -i - -s 640x480 -c:v libtheora -q:v 5 ./_test.ogv;mv ./_test.ogv ./test.ogv; sleep 0.01; done

Setup Python & OpenCV

sudo mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/_EXTERNALLY-MANAGED
python --version 
sudo apt update && sudo apt install libopencv-dev python3-opencv -y
sudo apt install -y python3-picamera2 #Bookworm only
pip install pytz imutils schedule screeninfo
## for jetson orin nano (jetpack 6.2)
cd ~
wget https://github.com/ArduCAM/MIPI_Camera/releases/download/v0.0.3/install_full.sh
chmod +x install_full.sh
./install_full.sh -m imx519
nvgstcapture-1.0
sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-libav
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, framerate=(fraction)30/1' !  nvvidconv ! 'video/x-raw, format=(string)RGBA' ! nveglglessink
##
python
{
  import cv2
  print(cv2.__version__)
}
python for GSTREAMER on Jetson
{
pipeline = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"
cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)
}

Run Godot

cd Download
./Godot_v4.4.1-stable_linux.arm64 --rendering-driver opengl3_es

Refs:

  1. https://www.waveshare.com/wiki/Raspberry_Pi_Camera_Module_3
  2. https://chuckmails.medium.com/enable-pi-camera-with-raspberry-pi4-ubuntu-20-10-327208312f6e
  3. https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/12MP-IMX708/#products-list
  4. https://qengineering.eu/install-opencv-on-raspberry-64-os.html
  5. https://godotengine.org/download/linux/
  6. https://docs.arducam.com/Nvidia-Jetson-Camera/Introduction-to-Arducam-Jetson-Cameras/
  7. https://docs.arducam.com/Nvidia-Jetson-Camera/Native-Camera/Quick-Start-Guide/

Author