技术专栏
在3519上实现LBP
目录 (Table of Contents)
[TOCM]
1 背景
LBP 计算示意图
LBP 计算公式
- IVE_LBP_CMP_NORMAL
- IVE_LBP_CMP_ABS
其中
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/720x576.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();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
<
给 sample_ive_main.c 添加内容
在 svp/ive
目录下
case 'c':
{
SAMPLE_IVE_DoLbp();
}
break;
- 1
- 2
- 3
- 4
- 5
给 sample_ive_main.h 添加内容
在 svp/ive/sample
目录下
/******************************************************************************
* function : show LBP sample
******************************************************************************/
HI_VOID SAMPLE_IVE_DoLbp(HI_VOID);
- 1
- 2
- 3
- 4
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!
- 1
- 2
- 3
最后是程序效果展示:
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
点赞
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包

相关专栏
-
浏览量:687次2024-09-13 11:55:31
-
浏览量:1319次2024-01-12 13:47:40
-
浏览量:765次2023-12-18 18:31:22
-
浏览量:9623次2018-10-24 14:39:45
-
浏览量:2283次2017-10-12 17:14:39
-
浏览量:1534次2023-04-19 09:11:58
-
浏览量:3623次2018-04-26 15:06:40
-
浏览量:1433次2023-11-27 14:02:37
-
浏览量:7823次2021-09-17 13:42:40
-
浏览量:8126次2022-07-29 18:09:52
-
浏览量:4021次2018-10-31 14:12:11
-
浏览量:1027次2024-01-08 18:13:05
-
浏览量:9569次2020-12-10 18:35:14
-
浏览量:1808次2020-02-28 18:49:51
-
浏览量:2772次2020-11-10 13:48:28
-
浏览量:4839次2021-08-25 13:48:29
-
浏览量:1525次2023-07-27 10:19:06
-
浏览量:2271次2024-01-18 18:05:38
-
浏览量:4919次2021-09-08 16:03:36
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者

merz
您的支持将鼓励我继续创作!
打赏金额:
¥1

¥5

¥10

¥50

¥100

支付方式:

举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注