GX Camera Application Development Guide
1 Overview
This document applies to scenarios where the camera hardware is correctly connected, the driver is properly installed, and the GX series camera has been successfully recognized.
The main objectives of this guide are to:
- Query the device information of the connected GX series camera
- Configure and prepare the camera operating modes
- Introduce several methods for previewing and capturing images
- Explain camera parameter configuration
- Provide guidance for customer-specific development
On the Rockchip platform, regardless of the method used to access the camera, it is necessary to complete device detection and media-ctl configuration before performing any further operations. Therefore, the following sections first cover device detection and media-ctl setup.
2 Device Detection and Environment Configuration
Here, we provide two scripts that can automatically retrieve key information about the connected camera.
2.1 probe_camera_info-rk.sh
This script is used to probe connected and successfully registered camera devices, retrieving underlying information such as the corresponding media device node, video device node, sub-device node, I²C bus, and device name.
After execution, an auto_camera_index.json file will be generated in the current directory, containing the retrieved information.
Example usage:
$ ./probe_camera_info-rk.sh
cat auto_camera_index.json
[
{
"media_node": "/dev/media0",
"video_node": "/dev/video0",
"video_subnode": "/dev/v4l-subdev2",
"media_entity_name": "m00_b_gxcam 7-003b",
"i2c_bus": "7"
}
]
Each {} block represents a single camera. If the board supports multiple camera modules, multiple {} blocks will be present in the file.
Explanation of Camera Information:
| Field | Name | Purpose | Usage |
|---|---|---|---|
| media_node | Media device node | Used to access the device within the media-controller framework | Used when configuring resolution and format via the media-ctl command
|
| video_node | Video capture device node | Standard V4L2 video device | Used with v4l2-ctl or customer applications to capture images
|
| video_subnode | V4L2 sub-device node | Used for configuring certain camera parameters | Accessed via v4l2-ctl commands
|
| media_entity_name | Media entity name | Describes the device, e.g., "m00_b_gxcam 7-003b"
|
Used when setting resolution and format with media-ctl
|
| i2c_bus | I²C bus | Indicates the I²C bus to which the device is connected | Used as the underlying communication channel for camera parameter configuration, e.g., by the gx_mipi_i2c.sh script
|
The media device node, video device node, sub-device node, I²C bus, and device name used in the following sections can all be replaced with the corresponding information obtained from the JSON file generated by this probe script.
2.2 gx_probe.sh
The gx_probe.sh script can configure environment variables with key information for a specific camera, including the I²C bus number, camera model, resolution (width and height), and frame rate. This simplifies subsequent use of media-ctl for format configuration.
The usage method is:
$ source ./gx_probe.sh <i2c_bus>
Example:
$ source ./gx_probe.sh 7
Found veye_gxcam camera on i2c-7.
Setenv CAMERAMODEL = GX-MIPI-IMX662
Setenv FPS = 60
Setenv WIDTH = 1920
Setenv HEIGHT = 1080
You can verify the environment variable output using, for example:
echo $CAMERAMODEL
Note: These environment variables are valid only for the current shell session.
3 Configuring Formats with media-ctl
3.1 Viewing the Topology with media-ctl
By using the "media-ctl" command, the current topology structure can be clearly displayed.
media-ctl -p -d /dev/media0
3.1.1 Link relationship
gx camera->rockchip-csi2-dphy0->rockchip-mipi-csi2->stream_cif_mipi_id0 - - ->DDR(/dev/video0)
The application can obtain images through the /dev/video0 node.
3.1.2 gx camera entity information
Take GX-MIPI-IMX662 as an example:
- entity 63: m00_b_gxcam 7-003b (1 pad, 1 link)
type V4L2 subdev subtype Sensor flags 0
device node name /dev/v4l-subdev2
pad0: Source
[fmt:UYVY8_2X8/1920x1080@10000/600000 field:none colorspace:rec709
crop:(0,0)/1920x1080]
-> "rockchip-csi2-dphy0":0 [ENABLED]
It can be seen that:
- The complete name of this Entity is: m00_b_gxcam 7-003b. (On the ROC-RK3566-PC, the name of this Entity is m00_b_gxcam 4-003b).
- It is a V4L2 subdev (Sub-Device) sensor.
- The corresponding node is /dev/v4l-subdev2. The application (such as v4l2-ctl) can open it and make configurations.
- Its output format is [UYVY8_2X8/1920x1080@10000/600000 field:none], where UYVY8_2X8 is a shortened form of an mbus-code. The supported mbus-codes will be listed in the next section.
- The current resolution is 1920x1080.
- The current frame interval is 10000/600000, which means the frame rate is 60.
The data format output by the camera can be modified through the "media-ctl" command.
3.2 Camera-supported MBUS code
The GX series cameras utilize the UYVY data format capability. For details, please refer to the data manuals of each model of the cameras.
| Format on datasheet | mbus-code for media-ctl | FourCC pixelformat for v4l2-ctl |
|---|---|---|
| UYVY | UYVY8_2X8 | UYVY |
3.3 Configuring Image Formats with media-ctl
The camera data format, resolution, and frame rate can be configured using the following command:
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam '"$I2C_BUS"'-003b":0[fmt:UYVY8_2X8/'"$WIDTH"'x'"$HEIGHT"'@1/'"$FPS"']'
"m00_b_gxcam 7-003b"specifies the full entity name of the camera.UYVY8_2X8is the mbus-code."$WIDTH"x"$HEIGHT"indicates the resolution.1/"$FPS"specifies the frame rate.
For example, for the GX-MIPI-IMX662, after substituting the variables, the command becomes:
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam 7-003b":0[fmt:UYVY8_2X8/1920x1080@1/60 field:none]'
This command allows you to configure the data format, resolution, and frame rate in a single step. Individual parameters can also be modified separately if needed.
Note: The node names in media-ctl can be adjusted according to the information in the JSON file generated by the probe script to configure different cameras.
4 veye_viewer
The veye_viewer is an open-source, Qt-based client application that allows users to easily evaluate cameras and configure parameters. Its operation logs, register listings, and open-source nature provide a convenient reference for users and support custom development.
The source code of veye_viewer can be downloaded here, or platform-specific executable programs are available directly in its release packages.
4.1 Configure parameters using v4l2-ctl
$ v4l2-ctl -d /dev/v4l-subdev2 -L
User Controls
trigger_mode 0x00981a01 (int) : min=0 max=4 step=1 default=0 value=0 flags=volatile, execute-on-write
trigger_src 0x00981a02 (int) : min=0 max=1 step=1 default=1 value=1 flags=volatile, execute-on-write
soft_trgone 0x00981a03 (button) : value=0 flags=write-only, execute-on-write
sync_role 0x00981a04 (int) : min=0 max=1 step=1 default=0 value=0 flags=volatile, execute-on-write
frame_rate 0x00981a05 (int) : min=0 max=60 step=1 default=60 value=60 flags=volatile, execute-on-write
Parameters can be set and get using the following methods.
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl [ctrl_type]=[val]
v4l2-ctl -d /dev/v4l-subdev2 --get-ctrl [ctrl_type]
All the above functions can be implemented using gx_mipi_i2c.sh.
Note that the above parameters cannot be modified during the capture process.
The following is an explanation of each parameter:
4.1.1 Trigger Mode
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_mode=[0-2]
0:Video streaming mode
1:Normal trigger mode.
4:Multi-camera synchronization mode.
4.1.2 Trigger Source
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=[0-1]
0: Software trigger mode.
1: Hardware trigger mode.
4.1.3 Software trigger command
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl soft_trgone=1
4.1.4 Set frame rate
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl frame_rate=[1-max]
The maximum frame rate is automatically updated as the resolution changed.
4.2 Set image format using media-ctl
use the following command to configure the camera's data format, resolution, and frame rate using media-ctl:
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam '"$I2C_BUS"'-003b":0[fmt:UYVY8_2X8/'"$WIDTH"'x'"$HEIGHT"'@1/'"$FPS"']'
Among them: "m00_b_gxcam '"$I2C_BUS"'-003b" refers to the complete name of the camera entity, UYVY8_2X8 is the mbus-code, '"$WIDTH"'x'"$HEIGHT"' indicates the resolution, 1/'"$FPS"' indicates the resolution frame rate.
For example, for GX-MIPI-IMX662, the command after variable replacement would be:
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam 7-003b":0[fmt:UYVY8_2X8/1920x1080@1/60 field:none]'
You can not only configure the data format, resolution, and frame rate in one command, but also modify them separately as needed.
4.3 Video Streaming mode
4.3.1 Set data format, resolution, frame rate
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam '"$I2C_BUS"'-003b":0[fmt:UYVY8_2X8/'"$WIDTH"'x'"$HEIGHT"'@1/'"$FPS"']'
4.3.2 Frame rate statistics
In streaming mode, the following commands can be used for frame rate statistics:
v4l2-ctl --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=-1 --stream-to=/dev/null
Or:
./yavta -c1000 --skip 0 -f UYVY -s ${WIDTH}x${HEIGHT} /dev/video0
4.3.3 Save image to file
- UYVY
v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to=uyvy-${WIDTH}x${HEIGHT}.yuv
Please refer to the description in the previous section for the image format.
4.3.4 Example of yavta
4.3.4.1 Install yavta
git clone git://git.ideasonboard.org/yavta.git
cd yavta;make
4.3.4.2 Save image to file
After setting data format, resolution, frame rate,run:
./yavta -c1 -Fuyvy-${WIDTH}x${HEIGHT}.yuv --skip 0 -f UYVY -s ${WIDTH}x${HEIGHT} /dev/video0
4.3.5 Example of import image to OpenCV
sudo apt install python3-opencv
See the samples directory on github for details.
python ./v4l2_opencv_show2.py --width 1920 --height 1080 --fps 60 --i2c 7
4.3.6 Example of gstreamer application
We provide several gstreamer routines that implement the preview function. See the samples directory on github for details.
4.4 Trigger mode
4.4.1 Set data format, resolution, frame rate
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam '"$I2C_BUS"'-003b":0[fmt:UYVY8_2X8/'"$WIDTH"'x'"$HEIGHT"'@1/'"$FPS"']'
4.4.2 Software trigger mode
4.4.2.1 Set mode
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_mode=1
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=0
4.4.2.2 Start acquisition
v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to=uyvy-${WIDTH}x${HEIGHT}.yuv
4.4.2.3 Perform soft trigger operation
In other shell terminals, you can execute the following command multiple times for multiple triggers.
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl soft_trgone=1
4.4.3 Hardware trigger mode
4.4.3.1 Set mode
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_mode=1
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_src=1
The gx_mipi_i2c.sh script can be used to set rich trigger parameters.
4.4.3.2 Start acquisition
v4l2-ctl -d /dev/video0 --set-fmt-video=width=$WIDTH,height=$HEIGHT,pixelformat=UYVY --stream-mmap --stream-count=1 --stream-to=uyvy-${WIDTH}x${HEIGHT}.yuv
4.4.3.3 Perform hardware trigger operation
Connect the appropriate trigger signal to the trigger pin of the camera and trigger it.
4.5 synchronous mode
4.5.1 Set data format, resolution, frame rate
media-ctl -d /dev/media0 --set-v4l2 '"m00_b_gxcam '"$I2C_BUS"'-003b":0[fmt:UYVY8_2X8/'"$WIDTH"'x'"$HEIGHT"'@1/'"$FPS"']'
4.5.2 Switch to synchronous mode
Note: The RK platform only supports one camera connection. Perform the following operations on both mainboard terminals to switch to synchronous mode.
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl trigger_mode=4
4.5.3 Set the camera as the master or slave.
master camera:
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl sync_role=0
slave camera:
v4l2-ctl -d /dev/v4l-subdev2 --set-ctrl sync_role=1
4.5.4 Start taking pictures
Several methods in the streaming mode can be used to take pictures.
5 i2c script for parameter configuration
We provide shell scripts to configure the parameters.
6 Question Feedback
We are committed to providing richer possibilities for image applications on embedded platforms. Therefore, our software for embedded platforms is based on the principle of open source.
If you have any questions or suggestions about our existing software, please feel free to submit them to the forum or email our technical staff at xumm#csoneplus.com.
7 References
- ROC-RK3566-PC Manual
https://wiki.t-firefly.com/en/ROC-RK3566-PC/
- ROC-RK3588S-PC Manual
https://wiki.t-firefly.com/en/ROC-RK3588S-PC/
- ROC-RK3576-PC Manual
https://wiki.t-firefly.com/en/ROC-RK3576-PC/
- Firefly Linux User Guide
https://wiki.t-firefly.com/en/Firefly-Linux-Guide/index.html
8 Document History
- 2025-11-28
Release 1st version.