透视变换是按照物体成像投影规律进行变换,即将物体重新投影到新的成像平面,常用于视觉畸变校正。
| 输入图像 | 参数 | 输出图像 |
|---|---|---|
![]() | kernel=0.90.050.00010.050.90.000115.015.01.1 | ![]() |
算子通过大小为3X3的转换矩阵参数,将输入图片按照透视的形式进行映射,映射关系如下:
dst(x,y)=src(M31x+M32y+M33M11x+M12y+M13,M31x+M32y+M33M21x+M22y+M23)
其中,dst 为输出图片,src 为输入图片,M 为3X3的转换矩阵。
int32_t hbVPWarpPerspective(hbUCPTaskHandle_t *taskHandle,
hbVPImage *dstImg,
hbVPImage const *srcImg,
hbVPPerspectiveParam const *perspectiveParam);
详细接口信息请查看 hbVPWarpPerspective 。
// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_warp_perspective.h"
// init Image, allocate memory for image data
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_width,
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_U8C1,
dst_width,
dst_height,
dst_stride,
dst_mem.virAddr,
dst_mem.phyAddr,
nullptr,
0,
0};
// init param
hbVPPerspectiveParam vp_param;
vp_param.transformMatrix[9] = {0};
vp_param.interpolation = HB_VP_INTER_LINEAR;
vp_param.borderType = HB_VP_BORDER_CONSTANT;
vp_param.borderValue = 0;
vp_param.isInverse = 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
hbVPWarpPerspective(&task_handle, &dst_img, &src_img, &vp_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);

