IVE使用模板总结

merz 2019-12-31 16:25:11 1683

目录 (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();
}
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
merz
红包 点赞 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
关于作者
merz

merz

暂无个性签名~

原创10
阅读3.7w
收藏3
点赞1
评论1
打赏用户 0
我要创作
分享技术经验,可获取创作收益
分类专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
merz
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区