Warp Perspective

Perspective transformation is in accordance with the object imaging projection law for transformation, that is, the object is re-projected to the new imaging plane, commonly used in visual aberration correction.

Operator Effect

Input ImageParameterOutput Image
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

Principle

The operator maps the input picture in the form of a perspective by means of a transformation matrix parameter of size 3X3 with the following mapping relationship:

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

Where dstdst is the output picture, srcsrc is the input picture and MM is the 3X3 transformation matrix.

API Interface

int32_t hbVPWarpPerspective(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPPerspectiveParam const *perspectiveParam);

For detailed interface information, please refer to hbVPWarpPerspective.

Usage

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