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/1920×1080.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/1280×720.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(); }
<

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:IVE使用模板总结 https://www.yhzz.com.cn/a/17123.html

上一篇 2023-05-19 00:58:29
下一篇 2023-05-19 01:56:28

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。