Warp Perspective

透视变换是按照物体成像投影规律进行变换,即将物体重新投影到新的成像平面,常用于视觉畸变校正。

算子效果

输入图像参数输出图像
imagekernel=[0.90.0515.00.050.915.00.00010.00011.1]\begin{aligned}kernel = \begin{bmatrix}0.9 & 0.05 & 15.0 \\ 0.05 & 0.9 & 15.0 \\ 0.0001 & 0.0001 & 1.1 \end{bmatrix}\end{aligned}image

原理

算子通过大小为3X3的转换矩阵参数,将输入图片按照透视的形式进行映射,映射关系如下:

dst(x,y)=src(M11x+M12y+M13M31x+M32y+M33,M21x+M22y+M23M31x+M32y+M33)dst(x,y)=src(\frac{M_{11} x+M_{12} y+M_{13}}{M_{31}x+M_{32}y+M_{33}},\frac{M_{21}x+M_{22}y+M_{23}}{M_{31}x+M_{32}y+M_{33}})

其中,dstdst 为输出图片,srcsrc 为输入图片,MM 为3X3的转换矩阵。

API接口

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);