This chapter introduces the GK7206 Intelligent Video Engine (IVE) sample, sample_ive. It demonstrates IVE image-processing algorithms including Sobel edge detection, Canny edge detection, GMM background modeling, motion detection, occlusion detection, and optical flow (St Lk).
The source lives in sample/ive/ in the SDK and serves as a reference template for intelligent video analysis.
| Parameter | Value |
|---|---|
index |
0~8 (see below) |
complete |
full mode (1) or fast mode (0) |
encode |
encoded output (1) or raw output (0) |
vo |
VO output (1) or VENC output (0) |
| index | Name | Data path | index | Name | Data path |
|---|---|---|---|---|---|
| 0 | Sobel | FILE to FILE | 5 | Canny | FILE to FILE |
| 1 | Edge | FILE to FILE | 6 | Od (occlusion) | VI to VENC |
| 2 | Gmm2 | FILE to FILE | 7 | St Lk (optical flow) | FILE to FILE |
| 3 | MemoryTest | FILE to FILE | 8 | dma | FILE to FILE |
| 4 | Motion detect | VI to VENC |
sample/ive/
├── Makefile # build script
└── sample_ive.c # main program
Before building this application, make sure the following are ready:
/sd_card# enter the sample directory
cd <SDK_PATH>/sample
# build the ive sample
make -C ive clean && make -C ive
# mount the SD card (recommended)
mkdir -p /sd_card
mount -t vfat /dev/mmcblk1p1 /sd_card
# transfer to the board over SCP
scp sample/ive/sample_ive root@<board-IP>:/sd_card/
# for the FILE cases, transfer the input image
scp input.jpg root@<board-IP>:/sd_card/
# make it executable
chmod +x /sd_card/sample_ive
# enter the SD card directory
cd /sd_card
# FILE case (Sobel edge detection)
./sample_ive 0
# VI case (motion detection)
./sample_ive 4 1 1 0
After a successful start (FILE cases) the terminal prints output like this:
sample_ive running
ive test index: 0
...
ive Sobel test success!
output file: /sd_card/output_sobel.yuv
This application uses the following architecture:
FILE case: input image -> IVE processing -> output image
VI case: Sensor -> VI -> VPSS -> IVE -> VENC -> RTSP streaming
// Step 1: IVE initialization
xmedia_ive_init();
// Step 2: create the IVE task
xmedia_ive_handle_t ive_handle = xmedia_ive_create();
// Step 3: configure the IVE task
switch(index) {
case 0: // Sobel
xmedia_ve_sobel(ive_handle, &src_img, &dst_img);
break;
case 5: // Canny
xmedia_ive_canny(ive_handle, &src_img, &dst_img);
break;
// ... other cases
}
// Step 4: destroy the IVE task
xmedia_ive_destroy(ive_handle);
// Step 5: IVE de-initialization
xmedia_ive_exit();
xmedia_ve_sobel_attr_t sobel_attr;
sobel_attr.edge_type = XMEDIA_IVE_SOBEL_EDGE_TYPE_BOTH; // horizontal + vertical
sobel_attr.bit_width = 8;
xmedia_ve_sobel(ive_handle, &src_img, &dst_img, &sobel_attr);
xmedia_ive_canny_attr_t canny_attr;
canny_attr.low_threshold = 50;
canny_attr.high_threshold = 150;
xmedia_ive_canny(ive_handle, &src_img, &dst_img, &canny_attr);
xmedia_ive_gmm_attr_t gmm_attr;
gmm_attr.max_bg_num = 3;
gmm_attr.variance_threshold = 2500;
xmedia_ive_gmm(ive_handle, &src_img, &bg_model, &fg_mask, &gmm_attr);
xmedia_ive_motion_detect_attr_t md_attr;
md_attr.width = 640;
md_attr.height = 480;
md_attr.threshold = 100;
xmedia_ive_motion_detect(ive_handle, &curr_img, &prev_img, &motion_result, &md_attr);
| Problem | Likely cause | Fix |
|---|---|---|
| FILE cases cannot find the input file | The input image was not copied to /sd_card | Copy the input image to /sd_card |
| VI cases fail to initialize | Sensor not connected | Check the sensor connection and configuration |
| IVE processing fails | Unsupported input format | Check that the input format is YUV420SP |