首页 > 技术知识 > 正文

目录 (Table of Contents)

[TOCM]

[TOC]

1 背景

LBP 计算示意图

在3519上实现LBP

LBP 计算公式

IVE_LBP_CMP_NORMAL

在3519上实现LBP1

IVE_LBP_CMP_ABS

在3519上实现LBP2

其中 I(x, y) 对应 pstSrc , lpb(x, y) 对应 pstDst ,thr 对应 pstLbpCtrl→ un8BitThr 。

2 主要程序

对 LBP 算子的使用主要是参考了win10下的 Hi3519A V100R001C02SPC010\SVP_PC\HiIVE_PC_V2.1.0.7_64bit\sample\LBP 目录下的程序,其实就是照葫芦画瓢咯。

编辑 sample_ive_lbp.c

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <signal.h> #include <semaphore.h> #include <pthread.h> #include <math.h> #include <time.h> #include “sample_comm_ive.h” typedef struct hiSAMPLE_IVE_LBP_S { IVE_SRC_IMAGE_S stSrc; //input frame IVE_DST_IMAGE_S stDst; //output frame FILE* pFpSrc; //read from pFpSrc FILE* pFpDst; //write to pFpDst }SAMPLE_IVE_LBP_S; static SAMPLE_IVE_LBP_S s_stLbp; static HI_VOID SAMPLE_IVE_Lbp_Uninit(SAMPLE_IVE_LBP_S *pstLbp) { IVE_MMZ_FREE(pstLbp->stSrc.au64PhyAddr[0], pstLbp->stSrc.au64VirAddr[0]); IVE_MMZ_FREE(pstLbp->stDst.au64PhyAddr[0], pstLbp->stDst.au64VirAddr[0]); IVE_CLOSE_FILE(pstLbp->pFpSrc); IVE_CLOSE_FILE(pstLbp->pFpDst); } static HI_S32 SAMPLE_IVE_Lbp_Init(SAMPLE_IVE_LBP_S *pstLbp, HI_U32 u32Width, HI_U32 u32Height, HI_CHAR *pchSrcFileName, HI_CHAR *pchDstFileName) { HI_S32 s32Ret = HI_SUCCESS; memset(pstLbp, 0, sizeof(SAMPLE_IVE_LBP_S)); s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstLbp->stSrc), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height); SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, LBP_INIT_FAIL, “Error(%#x),Create stSrc image failed!\n”, s32Ret); s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstLbp->stDst), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height); SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, LBP_INIT_FAIL, “Error(%#x),Create stDst image failed!\n”, s32Ret); s32Ret = HI_FAILURE; pstLbp->pFpSrc = fopen(pchSrcFileName, “rb”); SAMPLE_CHECK_EXPR_GOTO(NULL == pstLbp->pFpSrc, LBP_INIT_FAIL, “Error,Open file %s failed!\n”, pchSrcFileName); pstLbp->pFpDst = fopen(pchDstFileName, “wb”); SAMPLE_CHECK_EXPR_GOTO(NULL == pstLbp->pFpDst, LBP_INIT_FAIL, “Error,Open file %s failed!\n”, pchDstFileName); s32Ret = HI_SUCCESS; LBP_INIT_FAIL: if (HI_SUCCESS != s32Ret) { SAMPLE_IVE_Lbp_Uninit(pstLbp); } return s32Ret; } static HI_S32 SAMPLE_IVE_Lbp(IVE_SRC_IMAGE_S *pstSrc, IVE_DST_IMAGE_S *pstDst) { HI_S32 s32Ret; IVE_HANDLE IveHandle; IVE_LBP_CTRL_S stCtrl; memset(&stCtrl,0,sizeof(IVE_LBP_CTRL_S)); stCtrl.enMode = IVE_LBP_CMP_MODE_ABS; // stCtrl.enMode =IVE_LBP_CMP_MODE_NORMAL; stCtrl.un8BitThr.s8Val = 10; s32Ret = HI_MPI_IVE_LBP(&IveHandle, pstSrc, pstDst, &stCtrl, HI_FALSE); SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,”Error(%#x),HI_MPI_IVE_Lbp failed!\n”,s32Ret); return s32Ret; } static HI_S32 SAMPLE_IVE_LbpProc(SAMPLE_IVE_LBP_S *pstLbp) { HI_S32 s32Ret = HI_SUCCESS; s32Ret = SAMPLE_COMM_IVE_ReadFile(&(pstLbp->stSrc), pstLbp->pFpSrc); SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,”Error(%#x),Read src file failed!\n”,s32Ret); s32Ret = SAMPLE_IVE_Lbp(&pstLbp->stSrc, &pstLbp->stDst); SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,”Error(%#x),SAMPLE_IVE_Lbp failed!\n”,s32Ret); s32Ret = SAMPLE_COMM_IVE_WriteFile(&pstLbp->stDst, pstLbp->pFpDst); SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,”Error(%#x),write file failed!\n”,s32Ret); return s32Ret; } HI_VOID SAMPLE_IVE_DoLbp(HI_VOID) { HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32Width = 720; HI_U32 u32Height = 576; HI_CHAR pchSrcFileName[500]; HI_CHAR pchDstFileName[500]; snprintf(pchSrcFileName, sizeof(pchSrcFileName), “./data/input/img/pic/720x576_penguin.yuv”); snprintf(pchDstFileName, sizeof(pchDstFileName), “./data/output/lbp/720×576.yuv”); memset(&s_stLbp,0,sizeof(s_stLbp)); SAMPLE_COMM_IVE_CheckIveMpiInit(); s32Ret = SAMPLE_IVE_Lbp_Init(&s_stLbp, u32Width, u32Height, pchSrcFileName, pchDstFileName); SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, LBP_FAIL, “Error(%#x),SAMPLE_IVE_Lbp_Init failed!\n”, s32Ret); s32Ret = SAMPLE_IVE_LbpProc(&s_stLbp); if (HI_SUCCESS == s32Ret) { SAMPLE_PRT(“Process success!\n”); } SAMPLE_IVE_Lbp_Uninit(&s_stLbp); memset(&s_stLbp,0,sizeof(s_stLbp)); LBP_FAIL: SAMPLE_COMM_IVE_IveMpiExit(); }
<

sample_ive_main.c 添加内容

在 svp/ive 目录下

case c: { SAMPLE_IVE_DoLbp(); } break;

sample_ive_main.h 添加内容

在 svp/ive/sample 目录下

/****************************************************************************** * function : show LBP sample ******************************************************************************/ HI_VOID SAMPLE_IVE_DoLbp(HI_VOID); 3 测试

编译程序

cd /nfs/mpp/sample

make

然后报一大串 warning …

准备图片

找到 Hi3519A V100R001C02SPC010\SVP_PC\HiIVE_PC_V2.1.0.7_64bit\sample\data\img\shitomasi

目录下的 penguin.jpg

然后按照海思Hi3519A开发(5.梳理海思文档与运行sample代码)将图片转换成 yuv 格式

测试

在 Hi3519A 上输入 ./sample_ive_main c

/nfsroot/mpp/sample/svp/ive # ./sample_ive_main c time: 0.000170 s [LBPSample]-96: Process success!

最后是程序效果展示:

在3519上实现LBP3

猜你喜欢