Note

This is the documentation for the latest development branch and may refer to features that are not available in released versions. If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

VICAP Sensor Demo#

Introduction#

This example sample_vicap_sensor demonstrates how to use the K230’s VICAP (Video Capture) module for camera image acquisition and display. The VICAP module supports multiple camera sensors and can implement video input, image capture, Dump, and other functions.

Function Description#

VICAP Functions#

This example demonstrates the main functions of the VICAP module:

  • Camera Initialization: Automatically detect and initialize the camera sensor

  • Image Acquisition: Real-time image data acquisition

  • Resolution Configuration: Support custom sensor resolution and frame rate

  • Aspect Ratio Adaptation: Automatically adjust output based on screen ratio, keeping the image undistorted

  • Dual Channel Output:

    • CHN0: Used for Dump (supports YUV/RGB/RAW multiple formats)

    • CHN1: Used for preview display (YUV420SP)

  • Exposure Control: Support auto and manual exposure (in microseconds)

  • Gain Control: Support manual analog gain

  • White Balance: Support auto white balance (AWB)

  • HDR: Support HDR function

  • DNR3: Support 3D noise reduction (enabled by default)

  • Dewarp: Support image distortion correction

  • Scene Mode: Support scene configuration loading

Supported Parameters#

Parameter

Description

Default Value

-c

Connector type (required)

None

-r

Rotation angle (0/90/180/270)

0

-s

CSI index (0-2)

2

-ae

AE status (0: disable, 1: enable)

1

-awb

AWB status (0: disable, 1: enable)

1

-hdr

HDR status (0: disable, 1: enable)

0

-dw

Dewarp status (0: disable, 1: enable)

0

-dnr3

DNR3 status (0: disable, 1: enable)

1

-exp

Manual exposure time (microseconds)

-

-again

Manual analog gain

-

-width

Sensor width

1920

-height

Sensor height

1080

-fps

Sensor frame rate

30

-ofmt

CHN0 output format (0:YUV, 1:RGB888, 2:RGB888P, 3:RAW)

0

-scene_name

Scene name

-

-scene_path

Scene configuration path

-

Interactive Commands#

After the program runs, the following commands can be used for interaction:

Command

Description

d

Dump one frame (from CHN0)

d <n>

Dump n frames (from CHN0)

q

Quit the program

Code Location#

src/rtsmart/examples/mpp/sample_vicap_sensor/

Main files:

  • sample_vicap_sensor.c - Main program source code

Usage Instructions#

Compilation Method#

In the K230 RTOS SDK root directory, use make menuconfig to configure compilation options, select to compile the VICAP Sensor example into the firmware, and then compile the firmware.

Running Examples#

Basic Preview#

./sample_vicap_sensor.elf -c 20

Custom Resolution and Frame Rate#

./sample_vicap_sensor.elf -c 20 -width 1280 -height 720 -fps 60

Enable CHN0 Dump (YUV Format)#

./sample_vicap_sensor.elf -c 20 -ofmt 0

Enable CHN0 Dump (RGB888 Format)#

./sample_vicap_sensor.elf -c 20 -ofmt 1

Enable CHN0 Dump (RGB888P Format)#

./sample_vicap_sensor.elf -c 20 -ofmt 2

Enable CHN0 Dump (RAW10 Format)#

./sample_vicap_sensor.elf -c 20 -ofmt 3

Manual Exposure Setting#

# Set exposure time to 10000 microseconds (10ms), AE must be disabled
./sample_vicap_sensor.elf -c 20 -ae 0 -exp 10000

Manual Gain Setting#

# Set gain to 2.0, AE must be disabled
./sample_vicap_sensor.elf -c 20 -ae 0 -again 2.0

Disable DNR3#

./sample_vicap_sensor.elf -c 20 -dnr3 0

Rotate Display#

# Rotate 90 degrees
./sample_vicap_sensor.elf -c 20 -r 90

Load Scene Configuration#

./sample_vicap_sensor.elf -c 20 -scene_name day -scene_path /etc/vicap/day/

Interactive Operations#

After the program starts, the command menu will be displayed:

Preview running.
CHN0: dump (format=0), CHN1: preview
Commands: d=dump 1 frame, d <n>=dump n frames, q=quit

---------------------------------------
 Input command:
   d      - Dump one frame
   d <n>  - Dump n frames
   q      - Quit
---------------------------------------
Command:

Enter d or d 5 to dump the image to a file.

Viewing Results#

After the program runs, it will:

  • Detect and initialize the camera sensor

  • Get sensor resolution and exposure range

  • Calculate output resolution based on screen aspect ratio (maintaining aspect ratio)

  • Configure VICAP dual channels (CHN0 for Dump, CHN1 for Preview)

  • Bind VICAP to VO display layer

  • Start image capture and display

Output example:

INFO: Sensor resolution: 1920x1080
INFO: Sensor fd = 5
sample_vicap_sensor: connector=20, screen_size=1920x1080, output_size=1920x1080, layer=1, rotate=0, csi=2
Aspect ratio mode: sensor=1.78, screen=1.78
CHN0 format: 0 (0=yuv, 1=rgb888, 2=rgb888p, 3=raw)
Fullscreen mode (offset_x=0, offset_y=0)
VICAP features: AE=1, AWB=1, HDR=0, Dewarp=0, DNR3=1
Bind VICAP(dev=0, ch=1) -> VO(layer=1) OK
Starting VICAP stream on dev0 ch0 ...
INFO: Manual exposure set to 10000 us (0.010000 sec), range: 0.000030-0.033333 sec
Preview running.
CHN0: dump (format=0), CHN1: preview
Commands: d=dump 1 frame, d <n>=dump n frames, q=quit

Dump file save format:

vicap_dev0_chn0_1920x1080_0000.yuv420sp
vicap_dev0_chn0_1920x1080_0001.yuv420sp
...

Tips

  • When setting manual exposure, AE must be turned off first (-ae 0), otherwise an error will occur.

  • The exposure value must be within the range supported by the sensor, and the program will automatically check and prompt the valid range.

  • CHN0 is used for Dump and supports multiple formats; CHN1 is used for Preview and is fixed in YUV420SP format.

  • The output resolution will be automatically adjusted according to the screen aspect ratio, keeping the image undistorted.

  • Width and height will be automatically adjusted to a multiple of 8 (hardware requirement).

Notes

  • When using the -exp parameter, -ae 0 must be set at the same time.

  • When using the -again parameter, -ae 0 must be set at the same time.

  • The exposure value unit is microseconds (us), for example, 10000 means 10ms.

  • The gain value range is the range supported by the sensor, and the program will automatically check and prompt the valid range.

  • The Dump function is triggered through interactive commands and is not configured in the command-line parameters.

  • Width and height will be automatically adjusted to a multiple of 8 (hardware requirement).

  • You can use the command list_connector to view supported screen types

  • You can use list_sensor to view supported sensor types

Comments list
Comments
Log in