RoiResize算子功能为将输入图片按照ROI区域进行裁剪,然后将裁剪后的ROI区域等比例缩放到预定目标尺寸,最后对短边部分按照预置参数进行padding, 常用于对图片中的ROI区域提取并调整输出尺寸。算子支持双线性插值和最临近插值两种方式,不同的插值方式生成的图片结果也会有所差异。
| 输入图像 | 参数 | 输出图像 |
|---|---|---|
![]() | ROI= {100,200,399,359} | ![]() |
算子实现原理如下:
其中,resize过程请参考 hbVPResize 算子。
int32_t hbVPRoiResize(hbUCPTaskHandle_t *taskHandle,
hbVPImage *dstImg,
hbVPImage const *srcImg,
hbVPRoi const *roi,
hbVPRoiResizeParam const *roiResizeParam);
详细接口信息请查看 hbVPRoiResize。
// 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 = 0;
roi.top = 0;
roi.right = 1279;
roi.bottom = 719;
// 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, ¶m);
// 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);

