Roi Resize

The function of RoiResize operator is to crop the input picture according to the ROI area, then scale the cropped ROI area to the predefined target size, and finally padding the short side according to the predefined parameters, which is commonly used to extract the ROI area in the picture and adjust the output size. The operator supports both bilinear interpolation and closest proximity interpolation, and the results of the pictures generated by different interpolation methods will be different.

Operator Effect

Input ImageParameterOutput Image
imageROI = {100,200,399,359}
interpolation = HB_VP_INTER_LINEAR
paddingValue = {125,10,240}
image

Principle

The principle of operator realization is as follows:

VP5roiResize1

Among these, please refer to the Resize operator for the resize procedure.

API Interface

int32_t hbVPRoiResize(hbUCPTaskHandle_t *taskHandle, 
                      hbVPImage *dstImg, 
                      hbVPImage const *srcImg,
                      hbVPRoi const *roi,
                      hbVPRoiResizeParam const *roiResizeParam);

For detailed interface information, please refer to hbVPRoiResize.

Usage

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_roi_resize.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 roi
hbVPRoi roi;
roi.left = 100;
roi.top = 100;
roi.right = 399;
roi.bottom = 359;

// init param
hbVPRoiResizeParam param;
param.interpolation = HB_VP_INTER_LINEAR;
param.paddingValue[0] = 125;
param.paddingValue[1] = 10;
param.paddingValue[2] = 240;

// 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
hbVPRoiResize(&task_handle, &dst_img, &src_img, &roi, &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);