技术专栏
IVE使用模板总结
目录 (Table of Contents)
[TOCM]
@[toc]
对单张图片进行处理
#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 "sample_comm_ive.h"
//需要用到的文件和处理过程中的图片
typedef struct hiSAMPLE_IVE_TEST_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_TEST_S;
static SAMPLE_IVE_TEST_S s_stTest;
//解除初始化,释放初始化时申请的内存
static HI_VOID SAMPLE_IVE_Test_Uninit(SAMPLE_IVE_TEST_S *pstTest)
{
IVE_MMZ_FREE(pstTest->stSrc.au64PhyAddr[0], pstTest->stSrc.au64VirAddr[0]);
IVE_MMZ_FREE(pstTest->stDst.au64PhyAddr[0], pstTest->stDst.au64VirAddr[0]);
IVE_CLOSE_FILE(pstTest->pFpSrc);
IVE_CLOSE_FILE(pstTest->pFpDst);
}
//初始化,申请内存
static HI_S32 SAMPLE_IVE_Test_Init(SAMPLE_IVE_TEST_S *pstTest, HI_U32 u32Width, HI_U32 u32Height, HI_CHAR *pchSrcFileName, HI_CHAR *pchDstFileName)
{
HI_S32 s32Ret;
memset(pstTest, 0, sizeof(SAMPLE_IVE_TEST_S));
s32Ret = HI_FAILURE;
pstTest->pFpSrc = fopen(pchSrcFileName, "rb");
SAMPLE_CHECK_EXPR_GOTO(NULL == pstTest->pFpSrc, TEST_INIT_FAIL, "Error,Open file %s failed!\n", pchSrcFileName);
pstTest->pFpDst = fopen(pchDstFileName, "wb");
SAMPLE_CHECK_EXPR_GOTO(NULL == pstTest->pFpDst, TEST_INIT_FAIL, "Error,Open file %s failed!\n", pchDstFileName);
s32Ret = HI_SUCCESS;
s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstTest->stSrc), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, TEST_INIT_FAIL, "Error(%#x),Create Src image failed!\n", s32Ret);
s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstTest->stDst), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, TEST_INIT_FAIL, "Error(%#x),Create Dst image failed!\n", s32Ret);
TEST_INIT_FAIL:
if (HI_SUCCESS != s32Ret)
{
SAMPLE_IVE_Test_Uninit(pstTest);
}
return s32Ret;
}
//以LBP举例,里面的具体参数的设置需要参考《 HI_IVE参考.pdf 》
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_TestProc(SAMPLE_IVE_TEST_S *pstTest)
{
HI_S32 s32Ret = HI_SUCCESS;
//读文件到图片格式中
s32Ret = SAMPLE_COMM_IVE_ReadFile(&pstTest->stSrc, pstTest->pFpSrc);
SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,"Error(%#x),Read src1 file failed!\n",s32Ret);
//做IVE处理
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(&pstTest->stDst, pstTest->pFpDst);
SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,"Error(%#x),write file failed!\n",s32Ret);
return s32Ret;
}
HI_VOID SAMPLE_IVE_Test(HI_VOID)
{
HI_S32 s32Ret = HI_SUCCESS;
//图片格式信息和文件信息
HI_U32 u32Width = 1920;
HI_U32 u32Height = 1080;
HI_CHAR pchSrcFileName[500];
HI_CHAR pchDstFileName[500];
snprintf(pchSrcFileName, sizeof(pchSrcFileName), "./data/input/test/1920x1080.yuv");
snprintf(pchDstFileName, sizeof(pchDstFileName), "./data/output/test/test.yuv");
//初始化内存
memset(&s_stTest,0,sizeof(s_stTest));
//开启 MPI
SAMPLE_COMM_IVE_CheckIveMpiInit();
//初始化
s32Ret = SAMPLE_IVE_Test_Init(&s_stTest, u32Width, u32Height, pchSrcFileName, pchDstFileName);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, TEST_FAIL, "Error(%#x),SAMPLE_IVE_Test_Init failed!\n", s32Ret);
//处理
s32Ret = SAMPLE_IVE_TestProc(&s_stTest);
if (HI_SUCCESS == s32Ret)
{
SAMPLE_PRT("Process success!\n");
}
//解除初始化
SAMPLE_IVE_Test_Uninit(&s_stTest);
memset(&s_stTest,0,sizeof(s_stTest));
TEST_FAIL:
SAMPLE_COMM_IVE_IveMpiExit();
}
对单个视频进行处理
#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 <sys/prctl.h>
#include "sample_comm_ive.h"
#define SAMPLE_IVE_SFD_IMAGE_NUM 2
typedef struct hiSAMPLE_IVE_SFD_S
{
IVE_SRC_IMAGE_S astSrc[SAMPLE_IVE_SFD_IMAGE_NUM]; //input frame
IVE_DST_IMAGE_S stDst; //output frame
FILE* pFpSrc; //read from pFpSrc
FILE* pFpDst; //write to pFpDst
}SAMPLE_IVE_SFD_S;
static SAMPLE_IVE_SFD_S s_stSfd;
static HI_VOID SAMPLE_IVE_Sfd_Uninit(SAMPLE_IVE_SFD_S *pstSfd)
{
HI_U16 i;
for (i = 0; i < 2; i++)
{
IVE_MMZ_FREE(pstSfd->astSrc[i].au64PhyAddr[0], pstSfd->astSrc[i].au64VirAddr[0]);
}
IVE_MMZ_FREE(pstSfd->stDst.au64PhyAddr[0], pstSfd->stDst.au64VirAddr[0]);
IVE_CLOSE_FILE(pstSfd->pFpSrc);
IVE_CLOSE_FILE(pstSfd->pFpDst);
}
static HI_S32 SAMPLE_IVE_Sfd_Init(SAMPLE_IVE_SFD_S *pstSfd, HI_U32 u32Width, HI_U32 u32Height, HI_CHAR *pchSrcFileName, HI_CHAR *pchDstFileName)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_U16 i;
memset(pstSfd, 0, sizeof(SAMPLE_IVE_SFD_S));
for (i = 0; i < 2; i++)
{
s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstSfd->astSrc[i]), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, SFD_INIT_FAIL, "Error(%#x),Create src[%d] image failed!\n", s32Ret, i);
}
s32Ret = SAMPLE_COMM_IVE_CreateImage(&(pstSfd->stDst), IVE_IMAGE_TYPE_U8C1, u32Width, u32Height);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, SFD_INIT_FAIL, "Error(%#x),Create stDst image failed!\n", s32Ret);
s32Ret = HI_FAILURE;
pstSfd->pFpSrc = fopen(pchSrcFileName, "rb");
SAMPLE_CHECK_EXPR_GOTO(NULL == pstSfd->pFpSrc, SFD_INIT_FAIL, "Error,Open file %s failed!\n", pchSrcFileName);
pstSfd->pFpDst = fopen(pchDstFileName, "wb");
SAMPLE_CHECK_EXPR_GOTO(NULL == pstSfd->pFpDst, SFD_INIT_FAIL, "Error,Open file %s failed!\n", pchDstFileName);
s32Ret = HI_SUCCESS;
SFD_INIT_FAIL:
if (HI_SUCCESS != s32Ret)
{
SAMPLE_IVE_Sfd_Uninit(pstSfd);
}
return s32Ret;
}
//以LBP举例,里面的具体参数的设置需要参考《 HI_IVE参考.pdf 》
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_SfdProc(SAMPLE_IVE_SFD_S *pstSfd)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32FrmNum;
HI_S32 s32CurIdx = 0;
HI_U32 u32TotalFrm = 200;
for (u32FrmNum = 1; u32FrmNum < u32TotalFrm; u32FrmNum++)
{
SAMPLE_PRT("Proc Frame %d/%d\n",u32FrmNum,u32TotalFrm);
s32Ret = SAMPLE_COMM_IVE_ReadFile(&(pstSfd->astSrc[s32CurIdx]), pstSfd->pFpSrc);
SAMPLE_CHECK_EXPR_RET(HI_SUCCESS != s32Ret,s32Ret,"Error(%#x),Read src1 file failed!\n",s32Ret);
//做IVE处理
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(&pstSfd->stDst, pstSfd->pFpDst);
s32CurIdx = 1 - s32CurIdx; //change cur image to last image
}
return s32Ret;
}
HI_VOID SAMPLE_IVE_Sfd(HI_VOID)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32Width = 1280;
HI_U32 u32Height = 720;
HI_CHAR pchSrcFileName[IVE_FILE_NAME_LEN];
HI_CHAR pchDstFileName[IVE_FILE_NAME_LEN];
snprintf(pchSrcFileName, sizeof(pchSrcFileName), "./data/input/sfd/1280x720.yuv");
snprintf(pchDstFileName, sizeof(pchDstFileName), "./data/output/sfd/sfd.yuv");
memset(&s_stSfd,0,sizeof(s_stSfd));
SAMPLE_COMM_IVE_CheckIveMpiInit();
s32Ret = SAMPLE_IVE_Sfd_Init(&s_stSfd, u32Width, u32Height, pchSrcFileName, pchDstFileName);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, SFD_FAIL, "Error(%#x),SAMPLE_IVE_Sfd_Init failed!\n", s32Ret);
s32Ret = SAMPLE_IVE_SfdProc(&s_stSfd);
if (HI_SUCCESS == s32Ret)
{
SAMPLE_PRT("Process success!\n");
}
SAMPLE_IVE_Sfd_Uninit(&s_stSfd);
memset(&s_stSfd,0,sizeof(s_stSfd));
SFD_FAIL:
SAMPLE_COMM_IVE_IveMpiExit();
}
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
点赞
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包
暂无数据
相关专栏
-
浏览量:10301次2020-12-07 23:36:10
-
浏览量:5138次2020-08-25 18:07:54
-
浏览量:2485次2020-08-25 18:07:51
-
浏览量:1167次2023-08-29 15:52:13
-
浏览量:2521次2019-12-31 16:23:45
-
浏览量:3064次2017-11-28 12:33:29
-
浏览量:936次2023-12-22 14:13:56
-
浏览量:9334次2020-11-17 15:41:28
-
浏览量:5132次2020-05-08 15:46:11
-
浏览量:2196次2020-08-05 21:02:35
-
浏览量:6816次2021-01-16 15:50:24
-
浏览量:4683次2021-06-28 14:52:06
-
浏览量:583次2023-09-08 10:12:29
-
浏览量:674次2023-10-26 11:54:12
-
浏览量:2507次2020-06-12 19:39:57
-
浏览量:2399次2020-08-19 16:47:34
-
浏览量:7813次2017-11-16 16:26:57
-
浏览量:932次2023-12-22 11:24:42
-
浏览量:577次2023-09-07 09:51:17
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者
merz
您的支持将鼓励我继续创作!
打赏金额:
¥1
¥5
¥10
¥50
¥100
支付方式:
微信支付
打赏成功!
感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注