The optical flow processing sample uses the hbVPPyrDown, hbVPCornerHarris and hbVPOpticalFlowPyrLK interfaces, which involve LKOF and DSP hardware IP. It shows how to perform optical flow tracking on consecutive frame images for detailed implementation, please compare the practice with the sample source code.
Function overview

This sample realizes the function of feature point tracking on the image input of consecutive frames.
The input image is of NV12 type, which is converted to gray type and then used hbVPPyrDown to generate 5 layers of pyramid layers.
The first frame uses hbVPCornerHarris to generate harris corner points, and subsequent frames track the corner points generated in the first frame using hbVPOpticalFlowPyrLK.
Every 5 frames hbVPCornerHarris is called again to generate a priori eigenpoints to calibrate the tracking results.
The sample code process can be roughly divided into the following four steps, the detailed implementation of the sample source code please combine.
Allocate memory for input image and input-output feature points.
Prepare parameters for optical flow calculations.
The computations for each frame are performed sequentially, including generation of pyramid layers, corner detection and optical flow tracking.
Release memory resources.
Operation guide
The optical flow processing sample execution script is located in the ucp_tutorial/vp/vp_samples/script/04_optical_flow directory and contains the following script:
The command line in the run_optical_flow.sh script reads as follows:
The meanings of the command line parameters are as follows:
To use it, go to the vp_samples/script/04_optical_flow directory, and then directly execute run_optical_flow.sh. The execution method and log output are as follows:
Description of the results
At the end of the sample run, a visualization picture will be generated in the vp_samples/script/04_optical_flow directory, and the contents of the generated object for this sample is as follows:
The first frame will show the results of the harris feature point detection and the subsequent frames will show the optical flow tracking trajectory. Among them, the blue points are the feature points of the previous frame image, the red points are the feature points of the current frame image, and the green color is the optical flow trajectory. The tracking effect of the first and nth frame is shown as belows:
| First Frame | Frame n |
|---|---|
![]() | ![]() |