Flip

Flip算子通过像素的重映射实现了图像翻转的功能,形式包括水平方向翻转和垂直方向翻转。

算子效果

输入图像参数输出图像
imagemode=0image
imagemode=1image

原理

水平翻转公式如下:

dst(x,y)=src(widthx,y)dst(x,y)=src(width-x,y)

垂直翻转公式如下:

dst(x,y)=src(x,heighty)dst(x,y)=src(x,height-y)

其中,dstdst 为输出图像,srcsrc 为输入图像,heightheight 为图像高度,widthwidth 为图像宽度。

API接口

int32_t hbVPFlip(hbUCPTaskHandle_t *taskHandle,
                 hbVPImage *dstImg,
                 hbVPImage const *srcImg,
                 uint8_t flipMode);

详细接口信息请查看 hbVPFlip

使用方法

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_flip.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_stride,
                  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
uint8_t flip_mode{1};

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

// 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);