使用指定的滤波核对二维图像进行滤波(卷积),其中锚点默认为卷积核中心。
| 输入图像 | 参数 | 输出图像 |
|---|---|---|
![]() | kernel=0.003906250.0156250.027343750.0156250.003906250.0156250.06250.10156250.06250.0156250.027343750.10156250.093750.10156250.027343750.0156250.06250.10156250.06250.0156250.003906250.0156250.027343750.0156250.00390625 | ![]() |
dst(x,y)=0⩽x′<kernel.cols0⩽y′<kernel.rows∑kernel(x′,y′)∗src(x+x′−anchor.x,y+y′−anchor.y)
其中,dst 为输出图像,kernel 为滤波核,anchor 为锚点坐标,默认锚点为(-1, -1)
int32_t hbVPFilter2D(hbUCPTaskHandle_t *taskHandle,
hbVPImage *dstImg,
hbVPImage const *srcImg,
hbVPFilterKernel const *filterKernel,
hbVPFilter2DParam const *filter2DParam);
详细接口信息请查看 hbVPFilter2D 。
// Include the header
#include "hobot/hb_ucp.h"
#include "hobot/vp/hb_vp.h"
#include "hobot/vp/hb_vp_filter2d.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 kernel
hbUCPSysMem kernel_mem;
hbUCPMallocCached(&kernel_mem, 3 * 3 * sizeof(float32_t), 0);
hbVPFilterKernel kernel;
kernel.dataType = HB_VP_IMAGE_TYPE_F32C1;
kernel.width = 3;
kernel.height = 3;
kernel.dataPhyAddr = kernel_mem.phyAddr;
kernel.dataVirAddr = kernel_mem.virAddr;
// init param
hbVPFilter2DParam vp_param;
vp_param.borderType = HB_VP_BORDER_REPLICATE;
// 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
hbVPFilter2D(&task_handle, &dst_img, &src_img, &kernel, &vp_param);
// 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);
hbUCPFree(&kernel_mem);

