### Install Support Packages Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Installs necessary libraries for camera support, including zbar and OpenCV. ```bash sudo apt-get update && sudo apt-get install libzbar-dev libopencv-dev ``` ```bash sudo apt-get install python-opencv ``` -------------------------------- ### Install SDK Makefiles Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Installs the SDK makefiles for compiling camera applications. ```bash make install ``` -------------------------------- ### Compile Example Applications Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Cleans previous build artifacts and recompiles the example applications for the MIPI camera SDK. ```bash cd MIPI_Camera/RPI/ make clean && make ``` -------------------------------- ### Example Command Execution Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/JetsonNano_PTZ/README.md Demonstrates the command-line execution of the FocuserExample.py script on a Jetson Nano. ```bash lee@lee-desktop:~/MIPI_Camera/Jetson/JetsonNano_PTZ$ python FocuserExample.py -i 7 ``` -------------------------------- ### Install Jetson.GPIO Library Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/Multi-Camera Adapter/README.md Install the Jetson.GPIO library using pip. This is a prerequisite for using GPIO functionalities on Jetson devices. ```bash sudo pip install Jetson.GPIO ``` -------------------------------- ### Download and Install SDK Library Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Clones the MIPI Camera SDK repository and navigates to the Raspberry Pi specific directory. ```bash git clone https://github.com/ArduCAM/MIPI_Camera.git ``` ```bash cd MIPI_Camera/RPI/ ``` -------------------------------- ### Install Camera Library Source: https://github.com/arducam/mipi_camera/blob/master/RPI/python/imx230_postProcess/README.md Copy the Arducam MIPI camera library to the system's library path. ```Bash sudo cp libarducam_mipicamera.so /usr/lib ``` -------------------------------- ### Run Manual Focus Example Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX219/README.md Execute the manual focus example script. Specify the I2C bus using the -i flag. Note that I2C bus numbers differ between Jetson Nano B01 and Xavier NX. ```bash python FocuserExample.py -i 7 ``` -------------------------------- ### Record Video in H.264 Format Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This example demonstrates recording video in H.264 format using the 'video.c' application. ```bash $ ./video ``` -------------------------------- ### Preview Specified Camera Mode Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This example demonstrates how to preview the camera feed in a specified mode, which should be one of the modes listed by the './list_format' command. ```bash $ ./preview_setMode [mode] ``` -------------------------------- ### Install IMX477 Driver Package Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Install the IMX477 driver by executing the dpkg command with the provided .deb package. Ensure Jetvariety board is removed and IMX477 is connected directly to Jetson Nano. ```bash sudo dpkg -i xxx.deb ``` -------------------------------- ### Install Dependencies for Arducam MIPI Camera Source: https://github.com/arducam/mipi_camera/blob/master/RPI/python/README.md Install necessary Python packages and system dependencies for the Arducam MIPI camera library. Ensure these are installed before running the camera scripts. ```bash sudo pip install v4l2 ``` ```bash sudo pip install numpy ``` ```bash sudo apt-get install opencv-python ``` -------------------------------- ### Install WiringPi for Pi4 Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Installs the WiringPi library on Pi4 platform, which may be required for certain functionalities. It involves downloading a deb package and installing it. ```bash cd /tmp ``` ```bash wget https://project-downloads.drogon.net/wiringpi-latest.deb ``` ```bash sudo dpkg -i wiringpi-latest.deb ``` -------------------------------- ### Run Autofocus Example Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX219/README.md Execute the autofocus example script. Specify the I2C bus using the -i flag. Note that I2C bus numbers differ between Jetson Nano B01 and Xavier NX. ```bash python Autofocus.py -i 7 ``` -------------------------------- ### Install Arducam MIPI Camera Library Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Copy the Arducam MIPI camera shared library to the system's library directory. ```bash sudo cp /lib/libarducam_mipicamera /usr/lib/ ``` -------------------------------- ### Stream H.264 Video with RTP/Gstreamer (Gstreamer) Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This Gstreamer example streams H.264 video using RTP payload format over TCP. It involves specific Gstreamer commands on both the Raspberry Pi and the PC for setup. ```bash Raspberry pi side command: (x.x.x.x is your Raspberry Pi IP address) $ ./video2stdout | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=x.x.x.x port=5000 ``` ```bash PC side command: (x.x.x.x is your Raspberry Pi IP address) $ gst-launch-1.0 -v tcpclientsrc host=x.x.x.x port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! autovideosink sync=false ``` -------------------------------- ### Raw Image Capture with Callback Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This is a callback version of the 'capture_raw' example, allowing for asynchronous processing of raw image data. ```bash $ ./raw_callback ``` -------------------------------- ### Initialize ArduCAM MIPI Camera (C API) Source: https://context7.com/arducam/mipi_camera/llms.txt Initializes the camera hardware using the C API. Use `arducam_init_camera` for default setup or `arducam_init_camera2` for explicit configuration on multi-port boards. ```c #include "arducam_mipicamera.h" #include int main() { CAMERA_INSTANCE camera_instance; // Single-camera init (default interface) int res = arducam_init_camera(&camera_instance); if (res) { fprintf(stderr, "init camera failed, status = %d\n", res); return -1; } // Dual-camera init on Compute Module (camera port 0) struct camera_interface cam_iface = { .i2c_bus = 0, .camera_num = 0, .sda_pins = {28, 0}, .scl_pins = {29, 1}, .shutdown_pins= {31, 3}, .led_pins = {30, 2}, }; CAMERA_INSTANCE cam1; res = arducam_init_camera2(&cam1, cam_iface); if (res) { fprintf(stderr, "init camera2 failed, status = %d\n", res); return -1; } arducam_close_camera(camera_instance); arducam_close_camera(cam1); return 0; } ``` -------------------------------- ### Compile Arducamstill Test Application Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Compile the 'arducamstill' test application. This is typically done after installing the necessary libraries. ```bash make arducamstill ``` -------------------------------- ### Install Python 3.x Dependencies for Stereovision Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/Jetvariety/stereo_depth_demo/README.md Installs required packages for Python 3.x, including pip, the stereovision library, and development headers for Python 3. ```bash wget https://bootstrap.pypa.io/get-pip.py && sudo python3 get-pip.py sudo pip3 install stereovision sudo apt install libpython3-dev sudo pip3 install matplotlib ``` -------------------------------- ### Start and Stop Hardware Preview Source: https://context7.com/arducam/mipi_camera/llms.txt Initiates a hardware-accelerated live preview using the Broadcom GPU overlay. The `PREVIEW_PARAMS` struct allows configuration of fullscreen, opacity, and windowed mode positioning and sizing. Ensure `arducam_stop_preview` is called to release resources. ```c #include "arducam_mipicamera.h" #include #include int main() { CAMERA_INSTANCE cam; arducam_init_camera(&cam); arducam_set_mode(cam, 1); // Windowed preview at position (100,100), size 1280×720 PREVIEW_PARAMS params = { .fullscreen = 0, .opacity = 255, .window = {.x = 100, .y = 100, .width = 1280, .height = 720} }; if (arducam_start_preview(cam, ¶ms)) fprintf(stderr, "start preview failed\n"); printf("Previewing for 5 seconds...\n"); sleep(5); arducam_stop_preview(cam); arducam_close_camera(cam); return 0; } ``` -------------------------------- ### Configure User Permissions for GPIO Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/Multi-Camera Adapter/README.md Set up user permissions and groups to enable the Jetson GPIO Library. This involves creating a 'gpio' group, adding the current user to it, and installing custom udev rules. ```bash sudo groupadd -f -r gpio ``` ```bash sudo usermod -a -G gpio $USER ``` ```bash sudo cp /opt/nvidia/jetson-gpio/etc/99-gpio.rules /etc/udev/rules.d/ ``` ```bash sudo udevadm control --reload-rules && sudo udevadm trigger ``` ```bash sudo reboot ``` -------------------------------- ### arducam_start_preview / arducam_stop_preview Source: https://context7.com/arducam/mipi_camera/llms.txt Starts and stops a hardware-accelerated live preview window using the Broadcom GPU overlay. Preview parameters control fullscreen mode, opacity, and window position/size. ```APIDOC ## Raspberry Pi C API — Preview (`arducam_start_preview` / `arducam_stop_preview`) ### Description Starts a hardware-accelerated live preview window using the Broadcom GPU overlay. The `PREVIEW_PARAMS` struct controls fullscreen mode, window opacity (0=transparent, 255=opaque), and a destination rectangle for windowed mode. ### Usage Example ```c #include "arducam_mipicamera.h" #include #include int main() { CAMERA_INSTANCE cam; arducam_init_camera(&cam); arducam_set_mode(cam, 1); // Windowed preview at position (100,100), size 1280×720 PREVIEW_PARAMS params = { .fullscreen = 0, .opacity = 255, .window = {.x = 100, .y = 100, .width = 1280, .height = 720} }; if (arducam_start_preview(cam, ¶ms)) fprintf(stderr, "start preview failed\n"); printf("Previewing for 5 seconds...\n"); sleep(5); arducam_stop_preview(cam); arducam_close_camera(cam); return 0; } ``` ``` -------------------------------- ### Install Python 2.7 Dependencies for Stereovision Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/Jetvariety/stereo_depth_demo/README.md Installs necessary packages for Python 2.7, including the stereovision library and development headers for image manipulation. ```bash wget https://bootstrap.pypa.io/get-pip.py && sudo python get-pip.py sudo pip install stereovision sudo apt install libpng-dev sudo apt install libfreetype6-dev sudo apt install python-gi-cairo sudo pip install matplotlib ``` -------------------------------- ### Capture Image with Different Encoders Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This example captures images in different resolutions and supports JPEG, BMP, and PNG encoding. The 'capture.c' file allows for customization. ```bash $ ./capture [mode] ``` -------------------------------- ### Dual Camera Preview and Capture Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Demonstrates opening and previewing from two camera ports simultaneously on a Raspberry Pi Compute Module using 'preview-dualcam.c'. The 'capture-dualcam.c' example shows capturing images by switching between ports. Hardware wiring configuration is crucial. ```bash $ ./preview-dualcam or $ ./capture-dualcam ``` -------------------------------- ### Read and Write Sensor Registers Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This example illustrates direct reading and writing of sensor registers. Note that this may require modification based on the specific sensor's register addresses. ```bash $ ./read_write_sensor_reg ``` -------------------------------- ### Convert YUV to OpenCV Mat Format Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md The 'capture2opencv.cpp' example converts YUV camera data into an OpenCV Mat format for further processing and display. ```bash $ ./capture2opencv ``` -------------------------------- ### Arducamstill Preview with AWB and AE Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Starts a camera preview in mode 1, enabling auto white balance (AWB) and auto exposure (AE). Displays current sensor information. ```bash ./arducamstill -t 0 -m 1 -awb 1 -ae 1 ``` -------------------------------- ### Configure Stereo Hat Mode Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md After hardware setup for the Arducam stereo hat, run './list_format' to identify stereo modes (typically 7-11). This command then sets the camera to a specific stereo mode, demonstrated here with mode 7. ```bash pi@raspberrypi:~/MIPI_Camera/RPI $ ./preview_setMode 7 ``` -------------------------------- ### OV9281 External Trigger Synchronization Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md This example, 'ov9281_external_trigger.c', shows how to synchronize the OV9281 camera's capture events with external trigger signals. ```bash In the ov9281_external_trigger.c example, you can see how to synchronize the camera to the external trigger events. ``` -------------------------------- ### QR Code Detection with OpenCV Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Detects QR codes using OpenCV, especially with global shutter cameras like OV7251 or OV9281. Requires installation of 'libzbar-dev' and 'libopencv-dev'. The exposure value can be specified as an argument. ```bash $ ./qrcode_detection ``` -------------------------------- ### Navigate to Demo Directory Source: https://github.com/arducam/mipi_camera/blob/master/RPI/python/imx230_postProcess/README.md Change the current directory to the imx230 post-processing demo folder. ```Bash cd MIPI_Camera/RPI/python/imx230_postProcess ``` -------------------------------- ### Install Python SMBus Dependency Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/JetsonNano_PTZ/README.md Install the python-smbus package, which is required for I2C communication. Use python3-smbus for Python 3. ```bash sudo apt install python-smbus ``` ```bash sudo apt install python3-smbus ``` -------------------------------- ### Compile and Rebuild Project Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Compile the hello_video.bin utility by navigating to the specified directory and running the rebuild script. This is necessary for playing H264 files. ```bash $ cd /opt/vc/src/hello_pi && ./rebuild.sh ``` -------------------------------- ### Initialize MIPI Camera and Set Resolution (Python) Source: https://context7.com/arducam/mipi_camera/llms.txt Initializes the MIPI camera using the Python wrapper and sets the desired resolution. It also demonstrates how to retrieve supported formats and enable software-based auto exposure and auto white balance. ```python import arducam_mipicamera as arducam import v4l2 import numpy as np import cv2 import time camera = arducam.mipi_camera() camera.init_camera() # Set resolution and enumerate supported formats actual_w, actual_h = camera.set_resolution(1920, 1080) print(f"Resolution: {actual_w}x{actual_h}") for fmt in camera.get_support_formats(): print(f" mode={fmt['mode']} {fmt['width']}x{fmt['height']}") # Enable software AE / AWB camera.software_auto_exposure(enable=True) camera.software_auto_white_balance(enable=True) time.sleep(1) # let AE/AWB converge ``` -------------------------------- ### ISP Demo Preview Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Navigates to the ISP demo directory and runs the Python preview script. This demo relies on OpenCV. ```bash cd /MIPI_Camera/RPI/ISP python preview.py ``` -------------------------------- ### Arducamstill Help Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Displays the help information for the arducamstill application, showing available command-line options. ```bash ./arducamstill -? ``` -------------------------------- ### arducam_init_camera / arducam_init_camera2 Source: https://context7.com/arducam/mipi_camera/llms.txt Initializes the camera hardware. `arducam_init_camera` uses the default interface, while `arducam_init_camera2` allows explicit configuration for boards with multiple CSI ports. ```APIDOC ## Raspberry Pi C API — `arducam_init_camera` / `arducam_init_camera2` Initializes the camera hardware and returns a `CAMERA_INSTANCE` handle used by all subsequent API calls. `arducam_init_camera` uses the default camera interface, while `arducam_init_camera2` accepts a `camera_interface` struct for boards with multiple CSI ports (e.g., Compute Module), allowing explicit I2C bus, GPIO pin, and camera number selection. ```c #include "arducam_mipicamera.h" #include int main() { CAMERA_INSTANCE camera_instance; // Single-camera init (default interface) int res = arducam_init_camera(&camera_instance); if (res) { fprintf(stderr, "init camera failed, status = %d\n", res); return -1; } // Dual-camera init on Compute Module (camera port 0) struct camera_interface cam_iface = { .i2c_bus = 0, .camera_num = 0, .sda_pins = {28, 0}, .scl_pins = {29, 1}, .shutdown_pins= {31, 3}, .led_pins = {30, 2}, }; CAMERA_INSTANCE cam1; res = arducam_init_camera2(&cam1, cam_iface); if (res) { fprintf(stderr, "init camera2 failed, status = %d\n", res); return -1; } arducam_close_camera(camera_instance); arducam_close_camera(cam1); return 0; } ``` ``` -------------------------------- ### Navigate to Userland Directory Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Change the current directory to the cloned userland repository. ```bash cd userland ``` -------------------------------- ### Run Multi-Camera Adapter Demo Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/Multi-Camera Adapter/README.md Execute the demo script to preview cameras and capture snapshots. Use the -i flag to specify the I2C bus, which differs between Jetson Nano (1) and Jetson Xavier NX (8). ```python sudo python Multi-Camera-Adapter-Demo.py -i 1 ``` -------------------------------- ### Navigate to PTZ Directory Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/JetsonNano_PTZ/README.md Change the current directory to the Jetson Nano PTZ specific folder within the MIPI_Camera project. ```bash cd MIPI_Camera/Jetson/JetsonNano_PTZ/ ``` -------------------------------- ### Jetson: Initialize ArducamUtils and Capture Frame Source: https://context7.com/arducam/mipi_camera/llms.txt Initializes ArducamUtils for Jetson platforms, reads firmware and sensor info, configures the camera resolution, captures a frame, and converts it to BGR format using the utility's conversion function. ```python import cv2 import numpy as np from utils import ArducamUtils device_num = 0 # /dev/video0 cap = cv2.VideoCapture(device_num, cv2.CAP_V4L2) arducam_utils = ArducamUtils(device_num) # Print firmware and sensor info _, fw_ver = arducam_utils.read_dev(ArducamUtils.FIRMWARE_VERSION_REG) _, sensor_id = arducam_utils.read_dev(ArducamUtils.FIRMWARE_SENSOR_ID_REG) _, serial = arducam_utils.read_dev(ArducamUtils.SERIAL_NUMBER_REG) print(f"Firmware: {fw_ver}") print(f"Sensor ID: 0x{sensor_id:04X}") print(f"Serial: 0x{serial:08X}") # Disable OpenCV RGB auto-conversion when sensor is RAW if arducam_utils.convert2rgb == 0: cap.set(cv2.CAP_PROP_CONVERT_RGB, 0) # Set resolution cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) # Capture and convert one frame ret, frame = cap.read() if ret: if arducam_utils.convert2rgb == 0: w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) frame = frame.reshape(h, w) bgr = arducam_utils.convert(frame) # handles bit-depth scaling + debayer cv2.imwrite("jetson_frame.png", bgr) print(f"Frame saved: {bgr.shape}") # Write to sensor register via V4L2 ioctl arducam_utils.write_sensor(0x3820, 0x0000) val = arducam_utils.read_sensor(0x3820) print(f"Sensor reg 0x3820 = 0x{val:04X}") cap.release() ``` -------------------------------- ### Clone MIPI Camera Repository Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/JetsonNano_PTZ/README.md Download the source code for the MIPI camera project. ```bash git clone https://www.github.com/arducam/MIPI_Camera.git ``` -------------------------------- ### List Supported Camera Formats Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Use this command to check all resolutions supported by your camera sensor. This is often a prerequisite for other operations. ```bash pi@raspberrypi:~/MIPI_Camera/RPI $ ./list_format ``` -------------------------------- ### Run OpenCV GUI Application Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Launches the OpenCV GUI application for the MIPI camera, allowing for intuitive fine-tuning of image parameters. ```bash ./opencvGui ``` -------------------------------- ### Enable I2C Communication Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Makes the I2C enabling script executable and runs it to configure I2C communication. ```bash chmod +x enable_i2c_vc.sh ``` ```bash ./enable_i2c_vc.sh ``` -------------------------------- ### Build Userland for aarch64 Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Build the userland library specifically for the aarch64 architecture using the provided build script. ```bash ./buildme --aarch64 ``` -------------------------------- ### Display IMX477 Camera Feed (1920x1080) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Use this pipeline to display a 1920x1080 video stream from the IMX477 camera. Adjust SENSOR_ID and FRAMERATE as needed. Framerate can range from 2 to 60fps. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvvidconv ! nvoverlaysink ``` -------------------------------- ### Display IMX477 Camera Feed (4032x3040) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md This pipeline displays a 4032x3040 video stream from the IMX477 camera, downscaled to 1920x1080 for output. Framerate can range from 2 to 30fps. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvvidconv ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvoverlaysink ``` -------------------------------- ### Play H264 File Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Play an H264 video file using the compiled hello_video.bin utility. Ensure the file path is correct. ```bash $ /opt/vc/src/hello_pi/hello_video/hello_video.bin test.h264 ``` -------------------------------- ### Test Camera with Arducamstill Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Run the 'arducamstill' application to test the camera functionality. The '-t 0' flag likely indicates a continuous capture or a very long timeout. ```bash ./aruducamstill -t 0 ``` -------------------------------- ### Arducamstill Capture Image Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Captures a single image after a 5-second preview and saves it as a JPG file named 'test.jpg'. ```bash ./arducamstill -t 5000 -m 1 -e jpg -o test.jpg ``` -------------------------------- ### Record IMX477 Video to MP4 (4032x3040) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Record a 4032x3040 video stream from the IMX477 camera to an MP4 file. Framerate can range from 2 to 30fps. The output filename will include the sensor ID. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4 ``` -------------------------------- ### Make Camera I2C Script Executable Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Grant execute permissions to the camera_i2c and rpi3-gpiovirtbuf scripts. This is often a prerequisite for running camera diagnostic tools. ```bash sudo chmod +x camera_i2c rpi3-gpiovirtbuf ``` -------------------------------- ### Run Arducam Still Image Capture Script Source: https://github.com/arducam/mipi_camera/blob/master/RPI/python/README.md Execute the arducamstill.py script to capture a still image using the Arducam MIPI camera. This script requires the libarducam_mipicamera.so library to be pre-installed. ```bash python3 arducamstill.py ``` -------------------------------- ### Clone Userland Repository Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Clone the userland repository from GitHub to your Raspberry Pi. ```bash git clone https://github.com/raspberrypi/userland ``` -------------------------------- ### Continuous H.264 Video Stream with Callback Source: https://context7.com/arducam/mipi_camera/llms.txt Sets up a callback function for continuous H.264 video streaming. The callback is invoked for each encoded buffer. Passing NULL stops the stream. Encoding parameters can be configured via `VIDEO_ENCODER_STATE`. ```c #include "arducam_mipicamera.h" #include #include static FILE *video_file = NULL; int video_cb(BUFFER *buf) { if (video_file && buf->length > 0) { fwrite(buf->data, buf->length, 1, video_file); } return 0; // buffer is auto-released after callback returns } int main() { CAMERA_INSTANCE cam; arducam_init_camera(&cam); arducam_set_mode(cam, 1); video_file = fopen("output.h264", "wb"); VIDEO_ENCODER_STATE enc = { .encoding = VIDEO_ENCODING_H264, .bitrate = 4000000, // 4 Mbps .intraperiod = 30, // keyframe every 30 frames .quantisationParameter = 0, .bInlineHeaders = 1, .profile = VIDEO_PROFILE_H264_HIGH, .level = VIDEO_LEVEL_H264_4, .inlineMotionVectors = 0, .intra_refresh_type = -1, .addSPSTiming = 0, .slices = 1, }; if (arducam_set_video_callback(cam, &enc, video_cb, NULL)) { fprintf(stderr, "set video callback failed\n"); return -1; } printf("Recording 5 seconds of H.264...\n"); sleep(5); // Stop encoding arducam_set_video_callback(cam, NULL, NULL, NULL); fclose(video_file); arducam_close_camera(cam); return 0; } ``` -------------------------------- ### Record IMX477 Video to MP4 (1920x1080) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Record a 1920x1080 video stream from the IMX477 camera to an MP4 file. Framerate can range from 2 to 60fps. The output filename will include the sensor ID. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4 ``` -------------------------------- ### Copy Shared Libraries Source: https://github.com/arducam/mipi_camera/blob/master/RPI/lib/aarch64/readme.md Copy the built shared libraries (.so files) from the build directory to the system's aarch64 library path. ```bash sudo cp build/lib/*.so /usr/lib/aarch64-linux-gnu/ ``` -------------------------------- ### Run Post-Processing Script Source: https://github.com/arducam/mipi_camera/blob/master/RPI/python/imx230_postProcess/README.md Execute the postProcess.py script to apply corrections to the IMX230 sensor data. ```Python python3 postProcess.py ``` -------------------------------- ### Python Wrapper — `mipi_camera` class Source: https://context7.com/arducam/mipi_camera/llms.txt A ctypes-based Python wrapper around `libarducam_mipicamera.so`, exposing the C API as Pythonic methods. Returned buffer objects provide access to image data and metadata. ```APIDOC ## Python Wrapper — `mipi_camera` class (Raspberry Pi) ### Description The `mipi_camera` class in `arducam_mipicamera.py` is a ctypes-based Python wrapper around `libarducam_mipicamera.so`, providing the full C API surface as Pythonic methods. The returned `buffer` objects expose `.as_array` (numpy array), `.data` (raw bytes), `.length`, `.flags`, and `.pts` properties. ### Usage Example ```python import arducam_mipicamera as arducam import v4l2 import numpy as np import cv2 import time camera = arducam.mipi_camera() camera.init_camera() # Set resolution and enumerate supported formats actual_w, actual_h = camera.set_resolution(1920, 1080) print(f"Resolution: {actual_w}x{actual_h}") for fmt in camera.get_support_formats(): print(f" mode={fmt['mode']} {fmt['width']}x{fmt['height']}") # Enable software AE / AWB camera.software_auto_exposure(enable=True) camera.software_auto_white_balance(enable=True) time.sleep(1) # let AE/AWB converge ``` ``` -------------------------------- ### Python Callback for H.264 Video Streaming Source: https://context7.com/arducam/mipi_camera/llms.txt Sets up a Python callback function to receive H.264 encoded video chunks and write them to a file. The callback is triggered for each encoded buffer. ```python import arducam_mipicamera as arducam import time camera = arducam.mipi_camera() camera.init_camera() camera.set_resolution(1920, 1080) video_file = open("output.h264", "wb") def video_cb(buf): video_file.write(buf.data) return 0 camera.set_video_callback( func=video_cb, encoding=arducam.VIDEO_ENCODING_H264, bitrate=8000000, # 8 Mbps intraperiod=30, profile=arducam.VIDEO_PROFILE_H264_HIGH, level=arducam.VIDEO_LEVEL_H264_4, bInlineHeaders=1, ) print("Recording 10 seconds...") time.sleep(10) # Stop stream camera.set_video_callback(func=None) video_file.close() print("Saved output.h264") camera.close_camera() ``` -------------------------------- ### Run Camera I2C Diagnostic Source: https://github.com/arducam/mipi_camera/blob/master/RPI/README.md Execute the camera_i2c script to gather diagnostic information, particularly useful for troubleshooting camera initialization issues. The output should be sent to support if problems persist. ```bash ./camera_i2c ``` -------------------------------- ### Capture IMX477 JPEG Snapshots (4032x3040) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Capture multiple JPEG snapshots at 4032x3040 resolution from the IMX477 camera. Framerate can range from 2 to 30fps. Snapshots are saved with sequential numbering. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode NUMBER_OF_SNAPSHOTS=20 gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg ``` -------------------------------- ### Switch Camera Channels with Arducam Multi-Camera Adapter Source: https://context7.com/arducam/mipi_camera/llms.txt Selects active camera channels (0-3) on a multi-camera adapter board by writing to CHANNEL_SWITCH_REG. Ensure ArducamUtils is initialized for the correct device. ```python import cv2 from utils import ArducamUtils device_num = 0 cap = cv2.VideoCapture(device_num, cv2.CAP_V4L2) arducam_utils = ArducamUtils(device_num) if arducam_utils.convert2rgb == 0: cap.set(cv2.CAP_PROP_CONVERT_RGB, 0) for channel in range(4): # Switch to camera channel 0–3 arducam_utils.write_dev(ArducamUtils.CHANNEL_SWITCH_REG, channel) print(f"Switched to channel {channel}") ret, frame = cap.read() if ret: if arducam_utils.convert2rgb == 0: w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) frame = frame.reshape(h, w) bgr = arducam_utils.convert(frame) cv2.imwrite(f"camera_{channel}.png", bgr) print(f" Saved camera_{channel}.png shape={bgr.shape}") cap.release() # Expected output: # Switched to channel 0 # Saved camera_0.png shape=(1080, 1920, 3) # Switched to channel 1 # ... ``` -------------------------------- ### Capture IMX477 JPEG Snapshots (1920x1080) Source: https://github.com/arducam/mipi_camera/blob/master/Jetson/IMX477/driver/README.md Capture multiple JPEG snapshots at 1920x1080 resolution from the IMX477 camera. Framerate can range from 2 to 60fps. Snapshots are saved with sequential numbering. ```bash SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode NUMBER_OF_SNAPSHOTS=20 gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg ```