Rotate

Rotate算子通过建立图像间像素的映射关系,计算得到旋转一定角度的输入图像,常用来进行图片调整。

算子效果

输入图像参数输出图像
imagerotate_code = HB_VP_ROTATE_90_CLOCKWISEimage
imagerotate_code = HB_VP_ROTATE_180_CLOCKWISEimage
rotate_code = HB_VP_ROTATE_90_COUNTERCLOCKWISEimage

原理

算子实现原理如下:

VP5rotate1

根据不同旋转角度,将输入图片映射到不同的旋转位置,算子的长宽符合以下约束:

{dst.width=src.widthdst.height=src.height180clockwise\begin{cases}dst.width=src.width\\dst.height=src.height\end{cases}180clockwise

{dst.height=src.widthdst.width=src.height90clockwise90counter_clockwise\begin{cases}dst.height=src.width\\dst.width=src.height\end{cases}90clockwise、90counter\_clockwise

API接口

int32_t hbVPRotate(hbUCPTaskHandle_t *taskHandle,
                   hbVPImage *dstImg,
                   hbVPImage const *srcImg,
                   hbVPRotateDegree rotateDegree);

详细接口信息请查看 hbVPRotate

使用方法

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_rotate.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};

// init param
hbVPRotateDegree rotate_code{HB_VP_ROTATE_90_CLOCKWISE};

int32_t dst_width{src_height};
int32_t dst_height{src_width};
int32_t dst_stride{src_stride};

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 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
hbVPRotate(&task_handle, &dst_img, &src_img, rotate_code);

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