Warp Affine

An affine transformation is the process of transforming a vector space into another vector space by performing a linear transformation (multiplying by a matrix) and adding a translation (adding a vector). The WarpAffine operator functions as an affine transformation of the input picture, including planar operations such as picture rotation, scaling, and translation. Project the picture as any parallelogram.

Operator Effect

Input ImageParameterOutput Image
imagerotation_angle = 45.0f
interpolation = HB_VP_INTER_LINEAR
borderType = HB_VP_BORDER_CONSTANT
image

Principle

The operator maps the input picture in the form of affine by means of a transformation matrix parameter of size 2X3 with the following mapping relation:

[XY]=[abcd][xy]+[ef]\begin{aligned}\begin{bmatrix}X \\Y \end{bmatrix}=\begin{bmatrix}a & b \\ c & d \end{bmatrix}\begin{bmatrix}x \\y \end{bmatrix}+\begin{bmatrix}e \\f \end{bmatrix}\end{aligned}

Among them x,y are the input image pixel coordinates, X,Y are the output image pixel coordinates, and a,b,c,d,e,f are the transformation matrices.

For the input picture, it is decomposed into multiple sub-pictures (red areas in the figure below) during the accelerated computation process, and each sub-picture has an independent mapping relationship, and the conversion coefficients are consistent with the original picture. The display is shown below:

image

Where the right side is the input picture and the left side is the output picture.

API Interface

int32_t hbVPWarpAffine(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPAffineParam const *affineParam);

For detailed interface information, please refer to hbVPWarpAffine.

Usage

// Include the header #include "hobot/hb_ucp.h" #include "hobot/vp/hb_vp.h" #include "hobot/vp/hb_vp_warp_affine.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 hbVPAffineParam vp_param; vp_param.transformMatrix[6]= {0}; vp_param.interpolation = HB_VP_INTER_LINEAR; vp_param.borderType = HB_VP_BORDER_CONSTANT; vp_param.borderValue = 0; vp_param.isInverse = 0; // 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 hbVPWarpAffine(&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);