Corner Harris

The algorithm implements the Harris keypoint detection operator for detecting keypoints and inferring image features.

Operator Effect

Input ImageParameterOutput Image
imageblockSize = 3
sensitivity = 0.04
kernelSize = 3
borderType = HB_VP_BORDER_REPLICATE
image

Principle

The calculation process is as follows:

dst(x,y)=det(A)ktrace(A)2dst(x,y)=det(A)-k*trace(A)^2

dstdst is the output picture.

trace(A)=AGx2+AGy2trace(A)=\displaystyle\sum_A {G_x}^2+\displaystyle\sum_A {G_y}^2

det(A)=AGx2AGy2(AGxGy)2\det(A) = \displaystyle\sum_{A} {G_x}^2 \displaystyle\sum_{A} {G_y}^2 - ( \displaystyle\sum_{A} G_x G_y )^2

Among them, GxG_x is the sobel convolution in the x-direction, GyG_y is the sobel convolution in the y-direction, and AA is the convolution window.

API Interface

int32_t hbVPCornerHarris(hbUCPTaskHandle_t *taskHandle,
                         hbVPImage *dstImg,
                         hbVPImage const *srcImg,
                         hbVPCornerHarrisParam const *cornerHarrisParam);

For detailed interface information, please refer to hbVPCornerHarris.

Usage

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_corner_harris.h"

// init Image, allocate memory for image data
hbUCPSysMem src_mem;
hbUCPSysMem src_mem;
hbUCPMallocCached(&src_mem, src_stride * src_height, 0);
hbVPImage src_img{HB_VP_IMAGE_FORMAT_Y,
                  HB_VP_IMAGE_TYPE_U8C1,
                  src_width,
                  src_height,
                  src_stride,
                  src_mem.virAddr,
                  src_mem.phyAddr,
                  nullptr,
                  0,
                  0};

hbUCPSysMem dst_mem;
hbUCPMallocCached(&dst_mem, dst_stride * dst_height, 0);
hbVPImage dst_img{HB_VP_IMAGE_FORMAT_Y,
                  HB_VP_IMAGE_TYPE_S32C1,
                  dst_width,
                  dst_height,
                  dst_stride,
                  dst_mem.virAddr,
                  dst_mem.phyAddr,
                  nullptr,
                  0,
                  0};

// init param
hbVPCornerHarrisParam corner_harris_param;
corner_harris_param.blockSize = 3;
corner_harris_param.sensitivity = 0.04;
corner_harris_param.kernelSize = 3;
corner_harris_param.borderType = HB_VP_BORDER_REPLICATE;

// init task handle and schedule param
hbUCPTaskHandle_t task_handle{nullptr};
hbUCPSchedParam sched_param;
HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);
sched_param.backend = HB_UCP_DSP_CORE_0;

// create task
hbVPCornerHarris(&task_handle, &dst_img, &src_img, &corner_harris_param);

// submit task
hbUCPSubmitTask(task_handle, &sched_param);

// wait for task done 
hbUCPWaitTaskDone(task_handle, 0);

// release task handle
hbUCPReleaseTask(task_handle);

// release memory
hbUCPFree(&src_mem);
hbUCPFree(&dst_mem);