Remap

The Remap operator remaps the image according to the input information based on the incoming specific mapping relationships, and can be applied to scenarios where the image is transformed in various ways in 2D space and 3D space. This operator is usually a bit less efficient in execution compared to specific image transformation operators such as transpose, resize, due to different acceleration implementations.

Operator Effect

Input ImageParameterOutput Image
image-image

Principle

The principle of remapping operator is to rearrange the input picture on the output picture according to the mapping relationship in the incoming parameter map to realize the reconstruction of the picture, the main formula is as follows:

dst(x,y)=src(mapx(x,y),mapy(x,y))dst(x,y)=src(map_x(x,y),map_y(x,y))

Among them, dstdst is the output picture and srcsrc is the input picture.

image

API Interface

int32_t hbVPRemap(hbUCPTaskHandle_t *taskHandle, hbVPImage *dstImg, hbVPImage const *srcImg, hbVPMapWrap_t mapWrap);

For detailed interface information, please refer to hbVPRemap.

Usage

// 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, &param, 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);