Integral

计算图像的积分图。

算子效果

示意图像
VP5out_integral

原理

算子的原理为累积从原点到点(X, Y)矩形中的像素值,将其作为点(X,Y)处的像素值,计算公式如下:

sum(X,Y)=x<X,y<Ysrc(x,y)sum(X,Y)=\displaystyle\sum_{x<X,y<Y}src(x,y)

在神经网络中,积分图的常见应用场景为获取一块区域的像素值积分,计算公式如下:

x1x<xx,y1y<y2image(x,y)=sum(x2,y2)sum(x1,y2)sum(x2,y1)+sum(x1,y1)\displaystyle\sum_{x_1\leqslant x<x_x,y_1\leqslant y<y_2}image(x,y)=sum(x_2,y_2)-sum(x_1,y_2)-sum(x_2,y_1)+sum(x_1,y_1)

API接口

int32_t hbVPIntegral(hbUCPTaskHandle_t *taskHandle,
                     hbVPImage *dstImg,
                     hbVPImage const *srcImg);

详细接口信息请查看 hbVPIntegral

使用方法

// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_integral.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_S32C1,
                  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
hbVPIntegral(&task_handle, &dst_img, &src_img);

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