Remap算子根据传入的特定映射关系,将图像按照输入信息进行重映射,可以应用于图像在2D空间、3D空间各种变换的场景。 该算子相较于特定的图像变换算子,例如transpose、resize,由于加速实现不同,通常在执行效率上更低一些。
| 输入图像 | 参数 | 输出图像 |
|---|---|---|
![]() | - | ![]() |
重映射算子的原理为根据传入参数map中的映射关系将输入图片重新排布在输出图片上,实现图片的重构,主体公式如下:
dst(x,y)=src(mapx(x,y),mapy(x,y))
其中, dst 是输出图片,src 是输入图片。

int32_t hbVPRemap(hbUCPTaskHandle_t *taskHandle,
hbVPImage *dstImg,
hbVPImage const *srcImg,
hbVPMapWrap_t mapWrap);
详细接口信息请查看 hbVPRemap。
// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_remap.h"
// init remap param
hbUCPSysMem custom_mem;
hbUCPMallocCached(&custom_mem, width * height * sizeof(double) * 2, 0);
hbVPRemapParam param;
param.srcHeight = height;
param.srcWidth = width;
param.mapHeight = height;
param.mapWidth = width;
param.mapPhyAddr = custom_mem.phyAddr;
param.mapVirAddr = custom_mem.virAddr;
param.dataType = HB_VP_IMAGE_TYPE_F64C2;
param.interpoType = HB_VP_INTER_LINEAR;
// init param
hbVPMapWrap_t vp_map_wrap{nullptr};
// create map
hbVPCreateMapWrap(&vp_map_wrap, ¶m, HB_UCP_CORE_ANY);
// init Image, allocate memory for image data
hbUCPSysMem src_mem;
hbUCPMallocCached(&src_mem, src_stride * src_height * 3 / 2, 0);
hbVPImage src_img{HB_VP_IMAGE_FORMAT_NV12,
HB_VP_IMAGE_TYPE_U8C1,
src_width,
src_height,
src_stride,
src_mem.virAddr,
src_mem.phyAddr,
reinterpret_cast<char *>(src_img.dataVirAddr) + src_stride * src_height,
src_img.dataPhyAddr + src_stride * src_height,
src_stride};
hbUCPSysMem dst_mem;
hbUCPMallocCached(&dst_mem, dst_stride * dst_height * 3 / 2, 0);
hbVPImage dst_img{HB_VP_IMAGE_FORMAT_NV12,
HB_VP_IMAGE_TYPE_U8C1,
dst_width,
dst_height,
dst_stride,
dst_mem.virAddr,
dst_mem.phyAddr,
reinterpret_cast<char *>(dst_img.dataVirAddr) + dst_stride * dst_height,
dst_img.dataPhyAddr + dst_stride * dst_height,
dst_stride};
// 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
hbVPRemap(&task_handle, &dst_img, &src_img, vp_map_wrap);
// submit task
hbUCPSubmitTask(task_handle, &sched_param);
// wait for task done
hbUCPWaitTaskDone(task_handle, 0);
// release task handle
hbUCPReleaseTask(task_handle);
// release map
hbVPReleaseMapWrap(vp_map_wrap);
// release memory
hbUCPFree(&custom_mem);
hbUCPFree(&src_mem);
hbUCPFree(&dst_mem);

