该算法实现了用于检测关键点和推断图像特征的Harris关键点检测算子。
| 输入图像 | 参数 | 输出图像 |
|---|---|---|
![]() | blockSize = 3 sensitivity = 0.04 kernelSize = 3 borderType = HB_VP_BORDER_REPLICATE | ![]() |
计算过程如下:
dst(x,y)=det(A)−k∗trace(A)2
其中,dst 为输出图片。
trace(A)=A∑Gx2+A∑Gy2
det(A)=A∑Gx2A∑Gy2−(A∑GxGy)2
其中,Gx 为x方向上的sobel卷积,Gy 为y方向上的sobel卷积,A 为卷积窗口。
int32_t hbVPCornerHarris(hbUCPTaskHandle_t *taskHandle,
hbVPImage *dstImg,
hbVPImage const *srcImg,
hbVPCornerHarrisParam const *cornerHarrisParam);
详细接口信息请查看 hbVPCornerHarris 。
// 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 = 1;
// 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);

