Hi3559 MPP学习记录(2)

2023-11-10 11:30
文章标签 学习 记录 mpp hi3559

本文主要是介绍Hi3559 MPP学习记录(2),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 基本概念
  • 一、sensor数据获取以及输出sensor分辨率、像素格式、帧率等信息
  • 二、实现多路VPSS分别进行裁剪、锐化、缩放、旋转的任务
  • 三、实现VO与VPSS绑定,测试VO的旋转、缩放功能,并输出VO设备的像素、帧率信息
  • 总结


基本概念

  • 视频输入设备(DEV)
  • 视频输入物理PIPE
  • 视频输入虚拟PIPE
    VI 的 PIPE 包含了 ISP 的相关处理功能,主要是对图像数据进行流水线处理,输出YUV 图像格式给通道
  • 视频输入物理通道(PHY_CHN)
  • 扩展通道(EXT_CHN)
    扩展通道是物理通道的扩展,扩展通道具备缩放、裁剪、鱼眼矫正功能

在这里插入图片描述

在hisi平台vi模块中,存在sensor -> dev -> pipe -> phy_chn -> ext_chn的关系


一、sensor数据获取以及输出sensor分辨率、像素格式、帧率等信息

  • 代码实现:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>#include "sample_comm.h"/******************************************************************************
* function : to process abnormal case
******************************************************************************/
void SAMPLE_VIO_HandleSig(HI_S32 signo)
{//当捕获到异常信号后触发的自定义函数如下,主要是对信号的重新定义以及系统退出资源的释放if (SIGINT == signo || SIGTERM == signo){SAMPLE_COMM_All_ISP_Stop();SAMPLE_COMM_SYS_Exit();printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");}exit(-1);
}HI_S32 SAMPLE_VIO_StartViVo(SAMPLE_VI_CONFIG_S* pstViConfig, SAMPLE_VO_CONFIG_S* pstVoConfig)
{HI_S32  s32Ret;s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("start vi failed!\n");return s32Ret;}s32Ret = SAMPLE_COMM_VO_StartVO(pstVoConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_VIO start VO failed with %#x!\n", s32Ret);goto EXIT;}return s32Ret;EXIT://VO失败了需要把VI一同停止SAMPLE_COMM_VI_StopVi(pstViConfig);return s32Ret;
}HI_S32 SAMPLE_VIO_StopViVo(SAMPLE_VI_CONFIG_S* pstViConfig, SAMPLE_VO_CONFIG_S* pstVoConfig)
{SAMPLE_COMM_VO_StopVO(pstVoConfig);SAMPLE_COMM_VI_StopVi(pstViConfig);return HI_SUCCESS;
}HI_S32 MY_SAMPLE_VIO(VO_INTF_TYPE_E enVoIntfType)
{// Embeded isp.HI_S32             s32Ret;     //返回值VI_DEV             ViDev               = 0;VI_PIPE            ViPipe              = 0;VI_CHN             ViChn               = 0;HI_S32             s32WorkSnsId        = 0;VO_DEV             VoDev               = SAMPLE_VO_DEV_DHD0;VO_CHN             VoChn               = 0;SIZE_S             stSize;     //结构体,宽、高VB_CONFIG_S        stVbConf;   //视频缓存池属性结构体,PIC_SIZE_E         enPicSize           = PIC_3840x2160; //图片分辨率,也就是定义的视频的每一帧的分辨率HI_U32             u32BlkSize;SAMPLE_VI_CONFIG_S stViConfig  = {0};  //设置VI模块属性的结构体SAMPLE_VO_CONFIG_S stVoConfig  = {0};  //设置VO模块属性的结构体combo_dev_t          ComboDev;DYNAMIC_RANGE_E    enDynamicRange = DYNAMIC_RANGE_SDR8;  //动态范围PIXEL_FORMAT_E     enPixFormat    = PIXEL_FORMAT_YVU_SEMIPLANAR_420;  //像素格式类型VIDEO_FORMAT_E     enVideoFormat  = VIDEO_FORMAT_LINEAR;  //视频格式类型COMPRESS_MODE_E    enCompressMode = COMPRESS_MODE_NONE;   //视频压缩数据格式VI_VPSS_MODE_E     enMastPipeMode = VI_ONLINE_VPSS_OFFLINE; //VI PIPE 和 VPSS 组的工作模式/************************************************step1:  Get all sensors information*************************************************/SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);ComboDev = SAMPLE_COMM_VI_GetComboDevBySensor(stViConfig.astViInfo[s32WorkSnsId].stSnsInfo.enSnsType, s32WorkSnsId);stViConfig.s32WorkingViNum                           = 1;stViConfig.as32WorkingViId[0]                        = 0;stViConfig.astViInfo[0].stSnsInfo.MipiDev            = ComboDev;stViConfig.astViInfo[0].stSnsInfo.s32BusId           = 0;stViConfig.astViInfo[0].stDevInfo.ViDev              = ViDev;stViConfig.astViInfo[0].stDevInfo.enWDRMode          = WDR_MODE_NONE;stViConfig.astViInfo[0].stPipeInfo.enMastPipeMode    = enMastPipeMode;stViConfig.astViInfo[0].stPipeInfo.aPipe[0]          = ViPipe;stViConfig.astViInfo[0].stPipeInfo.aPipe[1]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[2]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[3]          = -1;stViConfig.astViInfo[0].stChnInfo.ViChn              = ViChn;stViConfig.astViInfo[0].stChnInfo.enPixFormat        = enPixFormat;stViConfig.astViInfo[0].stChnInfo.enDynamicRange     = enDynamicRange;stViConfig.astViInfo[0].stChnInfo.enVideoFormat      = enVideoFormat;stViConfig.astViInfo[0].stChnInfo.enCompressMode     = enCompressMode;/************************************************step2:  Get  input size*************************************************/s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(stViConfig.astViInfo[s32WorkSnsId].stSnsInfo.enSnsType, &enPicSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");return s32Ret;}s32Ret = SAMPLE_COMM_SYS_GetPicSize(enPicSize, &stSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");return s32Ret;}else{SAMPLE_PRT("==============================================\n");SAMPLE_PRT("The resolution of the sensor is (%d x %d)\n", stSize.u32Width, stSize.u32Height);SAMPLE_PRT("The pixel format of the sensor is %d\n", enPixFormat);SAMPLE_PRT("==============================================\n");}/************************************************step3:  Init SYS and common VB(视频缓存池处理模块)*************************************************/hi_memset(&stVbConf, sizeof(VB_CONFIG_S), 0, sizeof(VB_CONFIG_S));stVbConf.u32MaxPoolCnt              = 2;u32BlkSize = COMMON_GetPicBufferSize(stSize.u32Width, stSize.u32Height, SAMPLE_PIXEL_FORMAT, DATA_BITWIDTH_10, COMPRESS_MODE_SEG, DEFAULT_ALIGN);stVbConf.astCommPool[0].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[0].u32BlkCnt   = 10;u32BlkSize = VI_GetRawBufferSize(stSize.u32Width, stSize.u32Height, PIXEL_FORMAT_RGB_BAYER_16BPP, COMPRESS_MODE_NONE, 32);stVbConf.astCommPool[1].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[1].u32BlkCnt   = 4;s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret){SAMPLE_PRT("system init failed with %d!\n", s32Ret);SAMPLE_COMM_SYS_Exit();return s32Ret;}s32Ret = SAMPLE_COMM_VI_SetParam(&stViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_COMM_SYS_Exit();return s32Ret;}/************************************************step4:  Init VI and VO*************************************************/SAMPLE_COMM_VO_GetDefConfig(&stVoConfig);s32Ret = SAMPLE_VIO_StartViVo(&stViConfig, &stVoConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_VIO_StartViVo failed witfh %d\n", s32Ret);goto EXIT;}// 获取PipeAttr信息,需要在系统初始化之后,否则报错VI_PIPE_ATTR_S stPipeAttr;s32Ret = HI_MPI_VI_GetPipeAttr(0, &stPipeAttr);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("HI_MPI_VI_GetPipeAttr failed!\n");SAMPLE_PRT("%x\n",s32Ret);  //输出错误码return s32Ret;}else{//这里输出了一个-1.......,就是默认值,但是默认值是多少啊?????? 30fpsSAMPLE_PRT("==============================================\n");HI_U32 rate;if(stPipeAttr.stFrameRate.s32SrcFrameRate == -1){rate = 30;}else{rate = stPipeAttr.stFrameRate.s32SrcFrameRate;}SAMPLE_PRT("The frame rate of the sensor is %d fps\n", rate);SAMPLE_PRT("==============================================\n");}/************************************************step5:  Bind VI and VO*************************************************/s32Ret = SAMPLE_COMM_VI_Bind_VO(ViPipe, ViChn, VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_Bind_VO failed with %#x!\n", s32Ret);goto EXIT1;}PAUSE();SAMPLE_COMM_VI_UnBind_VO(ViPipe, ViChn, VoDev, VoChn);   //解除bindEXIT1:SAMPLE_VIO_StopViVo(&stViConfig, &stVoConfig);EXIT:SAMPLE_COMM_SYS_Exit();return s32Ret;
}/******************************************************************************
* function    : main()
* Description : main
******************************************************************************/int main(int argc, char* argv[])
{HI_S32 s32Ret = HI_FAILURE;VO_INTF_TYPE_E enVoIntfType = VO_INTF_HDMI; //输出格式signal(SIGINT, SAMPLE_VIO_HandleSig);signal(SIGTERM, SAMPLE_VIO_HandleSig);s32Ret = MY_SAMPLE_VIO(enVoIntfType);if (HI_SUCCESS == s32Ret){SAMPLE_PRT("my_vio exit success!\n");}else{SAMPLE_PRT("my_vio exit abnormally!\n");}return s32Ret;
}
  • 运行结果:
    在这里插入图片描述

二、实现多路VPSS分别进行裁剪、锐化、缩放、旋转的任务

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>#include "sample_comm.h"/******************************************************************************
* function : to process abnormal case
******************************************************************************/
void SAMPLE_VIO_HandleSig(HI_S32 signo)
{//当捕获到异常信号后触发的自定义函数如下,主要是对信号的重新定义以及系统退出资源的释放if (SIGINT == signo || SIGTERM == signo){SAMPLE_COMM_All_ISP_Stop();SAMPLE_COMM_SYS_Exit();printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");}exit(-1);
}HI_S32 MY_SAMPLE_COMM_VPSS_Start(VPSS_GRP VpssGrp, HI_BOOL* pabChnEnable, VPSS_GRP_ATTR_S* pstVpssGrpAttr, VPSS_CHN_ATTR_S* pastVpssChnAttr, VPSS_CROP_INFO_S* pstCropInfo, ROTATION_E enRotation)
{VPSS_CHN VpssChn;HI_S32 s32Ret;HI_S32 j;s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, pstVpssGrpAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_CreateGrp(grp:%d) failed with %#x!\n", VpssGrp, s32Ret);return HI_FAILURE;}/***********************************************sharpen锐化************************************************/VPSS_GRP_SHARPEN_ATTR_S stGrpSharpenAttr;s32Ret = HI_MPI_VPSS_GetGrpSharpen(VpssGrp, &stGrpSharpenAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_GetGrpSharpen failed with %#x\n", s32Ret);return HI_FAILURE;}stGrpSharpenAttr.bEnable = HI_TRUE;   //其他都是默认值?应该s32Ret = HI_MPI_VPSS_SetGrpSharpen(VpssGrp, &stGrpSharpenAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetGrpSharpen failed with %#x\n", s32Ret);return HI_FAILURE;}/***************************************************************/for (j = 0; j < VPSS_MAX_PHY_CHN_NUM; j++)  //设置四个通道的属性并使能{if(HI_TRUE == pabChnEnable[j]){VpssChn = j;s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &pastVpssChnAttr[VpssChn]);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x\n", s32Ret);return HI_FAILURE;}// if(VpssChn == 0)    chn0是原图if(VpssChn == 1){// chn1做裁剪s32Ret = HI_MPI_VPSS_SetChnCrop(VpssGrp, VpssChn, pstCropInfo);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnCrop failed with %#x\n", s32Ret);return HI_FAILURE;}}if(VpssChn == 2){// chn2做旋转s32Ret = HI_MPI_VPSS_SetChnRotation (VpssGrp, VpssChn, enRotation);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnRotation failed with %#x\n", s32Ret);return HI_FAILURE;}}if(VpssChn == 3){// chn3做缩放// 这里输出视频到HDMI后,没有黑边,但是像素明显变了pastVpssChnAttr[VpssChn].u32Width = 256;//此处设置所需的图片像素大小   pastVpssChnAttr[VpssChn].u32Height = 256;s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &pastVpssChnAttr[VpssChn]);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr chn[%d] failed with %#x\n", VpssChn, s32Ret);return HI_FAILURE;}}s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);return HI_FAILURE;}}}s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);return HI_FAILURE;}return HI_SUCCESS;
}HI_S32 MY_SAMPLE_VIPO(VO_INTF_TYPE_E enVoIntfType)
{HI_S32                  s32Ret              = HI_SUCCESS;VI_DEV                  ViDev0              = 0;VI_PIPE                 ViPipe0             = 0;VI_CHN                  ViChn               = 0;HI_S32                  s32ViCnt            = 1;VPSS_GRP                VpssGrp0            = 0;VPSS_CHN                VpssChn[4]          = {VPSS_CHN0, VPSS_CHN1, VPSS_CHN2, VPSS_CHN3};VPSS_GRP_ATTR_S         stVpssGrpAttr       = {0};VPSS_CHN_ATTR_S         stVpssChnAttr[VPSS_MAX_PHY_CHN_NUM];HI_BOOL                 abChnEnable[VPSS_MAX_PHY_CHN_NUM] = {0};VO_DEV                  VoDev               = SAMPLE_VO_DEV_DHD0;VO_CHN                  VoChn               = 0;VO_INTF_SYNC_E          g_enIntfSync        = VO_OUTPUT_1024x768_60;HI_U32                  g_u32DisBufLen      = 3;PIC_SIZE_E              enPicSize           = PIC_1080P;WDR_MODE_E              enWDRMode           = WDR_MODE_NONE;DYNAMIC_RANGE_E         enDynamicRange      = DYNAMIC_RANGE_SDR8;PIXEL_FORMAT_E          enPixFormat         = PIXEL_FORMAT_YVU_SEMIPLANAR_420;VIDEO_FORMAT_E          enVideoFormat       = VIDEO_FORMAT_LINEAR;COMPRESS_MODE_E         enCompressMode      = COMPRESS_MODE_NONE;VI_VPSS_MODE_E          enMastPipeMode      = VI_ONLINE_VPSS_ONLINE;SIZE_S                  stSize;HI_U32                  u32BlkSize;VB_CONFIG_S             stVbConf;SAMPLE_VI_CONFIG_S      stViConfig;SAMPLE_VO_CONFIG_S      stVoConfig;SAMPLE_PRT("VPSS_MAX_PHY_CHN_NUM is %d!\n", VPSS_MAX_PHY_CHN_NUM);/************************************************step 1:  Get all sensors information, need one vi,and need one mipi --*************************************************/SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);stViConfig.s32WorkingViNum                           = s32ViCnt;stViConfig.as32WorkingViId[0]                        = 0;stViConfig.astViInfo[0].stSnsInfo.MipiDev            = SAMPLE_COMM_VI_GetComboDevBySensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType, 0);stViConfig.astViInfo[0].stSnsInfo.s32BusId           = 0;stViConfig.astViInfo[0].stDevInfo.ViDev              = ViDev0;stViConfig.astViInfo[0].stDevInfo.enWDRMode          = enWDRMode;stViConfig.astViInfo[0].stPipeInfo.enMastPipeMode    = enMastPipeMode;stViConfig.astViInfo[0].stPipeInfo.aPipe[0]          = ViPipe0;stViConfig.astViInfo[0].stPipeInfo.aPipe[1]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[2]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[3]          = -1;stViConfig.astViInfo[0].stChnInfo.ViChn              = ViChn;stViConfig.astViInfo[0].stChnInfo.enPixFormat        = enPixFormat;stViConfig.astViInfo[0].stChnInfo.enDynamicRange     = enDynamicRange;stViConfig.astViInfo[0].stChnInfo.enVideoFormat      = enVideoFormat;stViConfig.astViInfo[0].stChnInfo.enCompressMode     = enCompressMode;/************************************************step 2:  Get  input size*************************************************/s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType, &enPicSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed with %d!\n", s32Ret);return s32Ret;}s32Ret = SAMPLE_COMM_SYS_GetPicSize(enPicSize, &stSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed with %d!\n", s32Ret);return s32Ret;}/************************************************step3:  Init SYS and common VB*************************************************/hi_memset(&stVbConf, sizeof(VB_CONFIG_S), 0, sizeof(VB_CONFIG_S));stVbConf.u32MaxPoolCnt              = 2;u32BlkSize = COMMON_GetPicBufferSize(stSize.u32Width, stSize.u32Height, SAMPLE_PIXEL_FORMAT, DATA_BITWIDTH_10, COMPRESS_MODE_SEG, DEFAULT_ALIGN);stVbConf.astCommPool[0].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[0].u32BlkCnt   = 10;u32BlkSize = VI_GetRawBufferSize(stSize.u32Width, stSize.u32Height, PIXEL_FORMAT_RGB_BAYER_16BPP, COMPRESS_MODE_NONE, DEFAULT_ALIGN);stVbConf.astCommPool[1].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[1].u32BlkCnt   = 4;s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("system init failed with %d!\n", s32Ret);goto EXIT;}s32Ret = SAMPLE_COMM_VI_SetParam(&stViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_SetParam failed with %d!\n", s32Ret);goto EXIT;}/************************************************step 4: start VI*************************************************/s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_StartVi failed with %d!\n", s32Ret);goto EXIT3;}/************************************************step 5: start VPSS, need one grp*************************************************/stVpssGrpAttr.u32MaxW                        = stSize.u32Width;stVpssGrpAttr.u32MaxH                        = stSize.u32Height;stVpssGrpAttr.enPixelFormat                  = enPixFormat;stVpssGrpAttr.enDynamicRange                 = enDynamicRange;stVpssGrpAttr.stFrameRate.s32SrcFrameRate    = -1;stVpssGrpAttr.stFrameRate.s32DstFrameRate    = -1;HI_S32 i;for(i = 0; i < VPSS_MAX_PHY_CHN_NUM; i++){abChnEnable[i]                               = HI_TRUE;stVpssChnAttr[i].u32Width                    = stSize.u32Width;stVpssChnAttr[i].u32Height                   = stSize.u32Height;stVpssChnAttr[i].enChnMode                   = VPSS_CHN_MODE_USER;stVpssChnAttr[i].enCompressMode              = enCompressMode;stVpssChnAttr[i].enDynamicRange              = enDynamicRange;stVpssChnAttr[i].enPixelFormat               = enPixFormat;stVpssChnAttr[i].enVideoFormat               = enVideoFormat;stVpssChnAttr[i].stFrameRate.s32SrcFrameRate = -1;stVpssChnAttr[i].stFrameRate.s32DstFrameRate = -1;stVpssChnAttr[i].u32Depth                    = 1;stVpssChnAttr[i].bMirror                     = HI_FALSE;stVpssChnAttr[i].bFlip                       = HI_FALSE;stVpssChnAttr[i].stAspectRatio.enMode        = ASPECT_RATIO_NONE;}/***********************************************Crop裁剪************************************************/VPSS_CROP_INFO_S stCropInfo;stCropInfo.bEnable = HI_TRUE;stCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR; //绝对坐标模式stCropInfo.stCropRect.s32X = 0;stCropInfo.stCropRect.s32Y = 0;stCropInfo.stCropRect.u32Width = 1000;stCropInfo.stCropRect.u32Height = 1000;/***********************************************旋转************************************************/ROTATION_E enRotation = ROTATION_90;s32Ret = MY_SAMPLE_COMM_VPSS_Start(VpssGrp0, abChnEnable, &stVpssGrpAttr, stVpssChnAttr, &stCropInfo, enRotation);//s32Ret = SAMPLE_COMM_VPSS_Start(VpssGrp0, abChnEnable, &stVpssGrpAttr, stVpssChnAttr);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Start Grp0 failed with %d!\n", s32Ret);goto EXIT2;}/************************************************step 7:  start V0*************************************************/SAMPLE_COMM_VO_GetDefConfig(&stVoConfig);stVoConfig.VoDev                                    = VoDev;stVoConfig.enVoIntfType                             = enVoIntfType;stVoConfig.enIntfSync                               = g_enIntfSync;stVoConfig.enPicSize                                = enPicSize;stVoConfig.u32DisBufLen                             = g_u32DisBufLen;stVoConfig.enDstDynamicRange                        = enDynamicRange;stVoConfig.enVoMode                                 = VO_MODE_1MUX;s32Ret = SAMPLE_COMM_VO_StartVO(&stVoConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartVO failed with %d!\n", s32Ret);goto EXIT1;}/************************************************step 8:  VO bind VPSS*************************************************/s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[0], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The original image now displayed, press any key to view the cropped image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[0], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The cropped image now displayed, press any key to view the rotated image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[2], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The rotated image now displayed, press any key to view the zoomed image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[2], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[3], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The zoomed image now displayed, press any key to stop\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[3], stVoConfig.VoDev, VoChn);// PAUSE();// SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);
EXIT1:SAMPLE_COMM_VO_StopVO(&stVoConfig);
EXIT2:SAMPLE_COMM_VPSS_Stop(VpssGrp0, abChnEnable);
EXIT3:SAMPLE_COMM_VI_StopVi(&stViConfig);
EXIT:SAMPLE_COMM_SYS_Exit();return s32Ret;
}/******************************************************************************
* function    : main()
* Description : main
******************************************************************************/
int main(int argc, char* argv[])
{HI_S32 s32Ret = HI_FAILURE;VO_INTF_TYPE_E enVoIntfType = VO_INTF_HDMI; //输出格式signal(SIGINT, SAMPLE_VIO_HandleSig);signal(SIGTERM, SAMPLE_VIO_HandleSig);s32Ret = MY_SAMPLE_VIPO(enVoIntfType);if (HI_SUCCESS == s32Ret){SAMPLE_PRT("my_vipo exit success!\n");}else{SAMPLE_PRT("my_vipo exit abnormally!\n");}return s32Ret;
}

图像处理结果:(原图、裁剪、旋转90、缩放)
在这里插入图片描述


三、实现VO与VPSS绑定,测试VO的旋转、缩放功能,并输出VO设备的像素、帧率信息

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>#include "sample_comm.h"/******************************************************************************
* function : to process abnormal case
******************************************************************************/
void SAMPLE_VIO_HandleSig(HI_S32 signo)
{//当捕获到异常信号后触发的自定义函数如下,主要是对信号的重新定义以及系统退出资源的释放if (SIGINT == signo || SIGTERM == signo){SAMPLE_COMM_All_ISP_Stop();SAMPLE_COMM_SYS_Exit();printf("\033[0;31mprogram termination abnormally!\033[0;39m\n");}exit(-1);
}HI_S32 MY_SAMPLE_COMM_VPSS_Start(VPSS_GRP VpssGrp, HI_BOOL* pabChnEnable, VPSS_GRP_ATTR_S* pstVpssGrpAttr, VPSS_CHN_ATTR_S* pastVpssChnAttr, VPSS_CROP_INFO_S* pstCropInfo, ROTATION_E enRotation)
{VPSS_CHN VpssChn;HI_S32 s32Ret;HI_S32 j;s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, pstVpssGrpAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_CreateGrp(grp:%d) failed with %#x!\n", VpssGrp, s32Ret);return HI_FAILURE;}/***********************************************sharpen锐化************************************************/VPSS_GRP_SHARPEN_ATTR_S stGrpSharpenAttr;s32Ret = HI_MPI_VPSS_GetGrpSharpen(VpssGrp, &stGrpSharpenAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_GetGrpSharpen failed with %#x\n", s32Ret);return HI_FAILURE;}stGrpSharpenAttr.bEnable = HI_TRUE;   //其他都是默认值?应该s32Ret = HI_MPI_VPSS_SetGrpSharpen(VpssGrp, &stGrpSharpenAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetGrpSharpen failed with %#x\n", s32Ret);return HI_FAILURE;}/***************************************************************/for (j = 0; j < VPSS_MAX_PHY_CHN_NUM; j++){if(HI_TRUE == pabChnEnable[j]){VpssChn = j;s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &pastVpssChnAttr[VpssChn]);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x\n", s32Ret);return HI_FAILURE;}// if(VpssChn == 0)    chn0是原图if(VpssChn == 1){// chn1做裁剪s32Ret = HI_MPI_VPSS_SetChnCrop(VpssGrp, VpssChn, pstCropInfo);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnCrop failed with %#x\n", s32Ret);return HI_FAILURE;}}if(VpssChn == 2){// chn2做旋转s32Ret = HI_MPI_VPSS_SetChnRotation (VpssGrp, VpssChn, enRotation);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnRotation failed with %#x\n", s32Ret);return HI_FAILURE;}}if(VpssChn == 3){// chn3做缩放// 这里输出视频到HDMI后,没有黑边,但是像素明显变了pastVpssChnAttr[VpssChn].u32Width = 512;//此处设置所需的图片像素大小   pastVpssChnAttr[VpssChn].u32Height = 512;s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &pastVpssChnAttr[VpssChn]);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr chn[%d] failed with %#x\n", VpssChn, s32Ret);return HI_FAILURE;}}s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);return HI_FAILURE;}}}s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);return HI_FAILURE;}return HI_SUCCESS;
}HI_S32 MY_SAMPLE_COMM_VO_StartVO(SAMPLE_VO_CONFIG_S *pstVoConfig)
{RECT_S                 stDefDispRect  = {0, 0, 1920, 1080};SIZE_S                 stDefImageSize = {1920, 1080};/******************************************** VO device VoDev# information declaration.********************************************/VO_DEV                 VoDev          = 0;VO_LAYER               VoLayer        = 0;SAMPLE_VO_MODE_E       enVoMode       = 0;VO_INTF_TYPE_E         enVoIntfType   = VO_INTF_HDMI;VO_INTF_SYNC_E         enIntfSync     = VO_OUTPUT_1080P30;DYNAMIC_RANGE_E        enDstDyRg      = DYNAMIC_RANGE_SDR8;VO_PART_MODE_E         enVoPartMode   = VO_PART_MODE_SINGLE;VO_PUB_ATTR_S          stVoPubAttr    = {0};VO_VIDEO_LAYER_ATTR_S  stLayerAttr    = {0};HI_S32                 s32Ret         = HI_SUCCESS;if (NULL == pstVoConfig){SAMPLE_PRT("Error:argument can not be NULL\n");return HI_FAILURE;}VoDev          = pstVoConfig->VoDev;VoLayer        = pstVoConfig->VoDev;enVoMode       = pstVoConfig->enVoMode;enVoIntfType   = pstVoConfig->enVoIntfType;enIntfSync     = pstVoConfig->enIntfSync;enDstDyRg      = pstVoConfig->enDstDynamicRange;enVoPartMode   = pstVoConfig->enVoPartMode;/********************************* Set and start VO device VoDev#.*********************************/stVoPubAttr.enIntfType  = enVoIntfType;stVoPubAttr.enIntfSync  = enIntfSync;stVoPubAttr.u32BgColor  = pstVoConfig->u32BgColor;s32Ret = SAMPLE_COMM_VO_StartDev(VoDev, &stVoPubAttr);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartDev failed!\n");return s32Ret;}/******************************* Set and start layer VoDev#.********************************/s32Ret = SAMPLE_COMM_VO_GetWH(stVoPubAttr.enIntfSync,&stLayerAttr.stDispRect.u32Width, &stLayerAttr.stDispRect.u32Height,&stLayerAttr.u32DispFrmRt);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_GetWH failed!\n");SAMPLE_COMM_VO_StopDev(VoDev);return s32Ret;}stLayerAttr.bClusterMode     = HI_FALSE;stLayerAttr.bDoubleFrame    = HI_FALSE;stLayerAttr.enPixFormat       = pstVoConfig->enPixFormat;stLayerAttr.stDispRect.s32X = 0;stLayerAttr.stDispRect.s32Y = 0;/******************************// Set display rectangle if changed.********************************/if (0 != memcmp(&pstVoConfig->stDispRect, &stDefDispRect, sizeof(RECT_S))){stLayerAttr.stDispRect = pstVoConfig->stDispRect;}stLayerAttr.stImageSize.u32Width  = stLayerAttr.stDispRect.u32Width;stLayerAttr.stImageSize.u32Height = stLayerAttr.stDispRect.u32Height;stLayerAttr.stImageSize.u32Width  = stLayerAttr.stDispRect.u32Width;stLayerAttr.stImageSize.u32Height = stLayerAttr.stDispRect.u32Height;/******************************//Set image size if changed.********************************/if (0 != memcmp(&pstVoConfig->stImageSize, &stDefImageSize, sizeof(SIZE_S))){stLayerAttr.stImageSize = pstVoConfig->stImageSize;}stLayerAttr.enDstDynamicRange     = pstVoConfig->enDstDynamicRange;if (pstVoConfig->u32DisBufLen){s32Ret = HI_MPI_VO_SetDisplayBufLen(VoLayer, pstVoConfig->u32DisBufLen);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("HI_MPI_VO_SetDisplayBufLen failed with %#x!\n",s32Ret);SAMPLE_COMM_VO_StopDev(VoDev);return s32Ret;}}if (VO_PART_MODE_MULTI == enVoPartMode){s32Ret = HI_MPI_VO_SetVideoLayerPartitionMode(VoLayer, enVoPartMode);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("HI_MPI_VO_SetVideoLayerPartitionMode failed!\n");SAMPLE_COMM_VO_StopDev(VoDev);return s32Ret;}}/**************zoom***********************/stLayerAttr.stDispRect.u32Width = 256;stLayerAttr.stDispRect.u32Height  = 256;stLayerAttr.stImageSize.u32Width = stLayerAttr.stDispRect.u32Width;stLayerAttr.stImageSize.u32Height = stLayerAttr.stDispRect.u32Height; SAMPLE_PRT("==============================================\n");SAMPLE_PRT("The display resolution of VO is (%d x %d)\n", stLayerAttr.stDispRect.u32Width, stLayerAttr.stDispRect.u32Width);SAMPLE_PRT("The video display frame rate is %d\n", stLayerAttr.u32DispFrmRt);SAMPLE_PRT("==============================================\n");s32Ret = HI_MPI_VO_SetVideoLayerAttr(VoLayer, &stLayerAttr);if (s32Ret != HI_SUCCESS){SAMPLE_PRT("HI_MPI_VO_SetVideoLayerAttr failed with %#x!\n", s32Ret);SAMPLE_COMM_VO_StopDev(VoDev);return HI_FAILURE;}s32Ret = HI_MPI_VO_EnableVideoLayer(VoLayer);if (s32Ret != HI_SUCCESS){SAMPLE_PRT(" HI_MPI_VO_EnableVideoLayerfailed with %#x!\n", s32Ret);SAMPLE_COMM_VO_StopDev(VoDev);return HI_FAILURE;}/******************************* start vo channels.********************************/s32Ret = SAMPLE_COMM_VO_StartChn(VoLayer, enVoMode);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartChn failed!\n");SAMPLE_COMM_VO_StopLayer(VoLayer);SAMPLE_COMM_VO_StopDev(VoDev);return s32Ret;}/**************set rotation****************/s32Ret = HI_MPI_VO_SetChnRotation(VoLayer, 0, ROTATION_90);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("HI_MPI_VO_SetChnRotation failed with %#x!\n", s32Ret);return s32Ret;}/******************************* Start hdmi device.* Note : do this after vo device started.********************************/if(VO_INTF_HDMI == enVoIntfType){SAMPLE_COMM_VO_HdmiStartByDyRg(enIntfSync, enDstDyRg);}return HI_SUCCESS;
}HI_S32 MY_SAMPLE_VIPO(VO_INTF_TYPE_E enVoIntfType)
{HI_S32                  s32Ret              = HI_SUCCESS;VI_DEV                  ViDev0              = 0;VI_PIPE                 ViPipe0             = 0;VI_CHN                  ViChn               = 0;HI_S32                  s32ViCnt            = 1;VPSS_GRP                VpssGrp0            = 0;VPSS_CHN                VpssChn[4]          = {VPSS_CHN0, VPSS_CHN1, VPSS_CHN2, VPSS_CHN3};VPSS_GRP_ATTR_S         stVpssGrpAttr       = {0};VPSS_CHN_ATTR_S         stVpssChnAttr[VPSS_MAX_PHY_CHN_NUM];HI_BOOL                 abChnEnable[VPSS_MAX_PHY_CHN_NUM] = {0};VO_DEV                  VoDev               = SAMPLE_VO_DEV_DHD0;VO_CHN                  VoChn               = 0;VO_INTF_SYNC_E          g_enIntfSync        = VO_OUTPUT_1024x768_60;HI_U32                  g_u32DisBufLen      = 3;PIC_SIZE_E              enPicSize           = PIC_1080P;WDR_MODE_E              enWDRMode           = WDR_MODE_NONE;DYNAMIC_RANGE_E         enDynamicRange      = DYNAMIC_RANGE_SDR8;PIXEL_FORMAT_E          enPixFormat         = PIXEL_FORMAT_YVU_SEMIPLANAR_420;VIDEO_FORMAT_E          enVideoFormat       = VIDEO_FORMAT_LINEAR;COMPRESS_MODE_E         enCompressMode      = COMPRESS_MODE_NONE;VI_VPSS_MODE_E          enMastPipeMode      = VI_ONLINE_VPSS_ONLINE;SIZE_S                  stSize;HI_U32                  u32BlkSize;VB_CONFIG_S             stVbConf;SAMPLE_VI_CONFIG_S      stViConfig;SAMPLE_VO_CONFIG_S      stVoConfig;SAMPLE_PRT("VPSS_MAX_PHY_CHN_NUM is %d!\n", VPSS_MAX_PHY_CHN_NUM);/************************************************step 1:  Get all sensors information, need one vi,and need one mipi --*************************************************/SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);stViConfig.s32WorkingViNum                           = s32ViCnt;stViConfig.as32WorkingViId[0]                        = 0;stViConfig.astViInfo[0].stSnsInfo.MipiDev            = SAMPLE_COMM_VI_GetComboDevBySensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType, 0);stViConfig.astViInfo[0].stSnsInfo.s32BusId           = 0;stViConfig.astViInfo[0].stDevInfo.ViDev              = ViDev0;stViConfig.astViInfo[0].stDevInfo.enWDRMode          = enWDRMode;stViConfig.astViInfo[0].stPipeInfo.enMastPipeMode    = enMastPipeMode;stViConfig.astViInfo[0].stPipeInfo.aPipe[0]          = ViPipe0;stViConfig.astViInfo[0].stPipeInfo.aPipe[1]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[2]          = -1;stViConfig.astViInfo[0].stPipeInfo.aPipe[3]          = -1;stViConfig.astViInfo[0].stChnInfo.ViChn              = ViChn;stViConfig.astViInfo[0].stChnInfo.enPixFormat        = enPixFormat;stViConfig.astViInfo[0].stChnInfo.enDynamicRange     = enDynamicRange;stViConfig.astViInfo[0].stChnInfo.enVideoFormat      = enVideoFormat;stViConfig.astViInfo[0].stChnInfo.enCompressMode     = enCompressMode;/************************************************step 2:  Get  input size*************************************************/s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType, &enPicSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed with %d!\n", s32Ret);return s32Ret;}s32Ret = SAMPLE_COMM_SYS_GetPicSize(enPicSize, &stSize);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed with %d!\n", s32Ret);return s32Ret;}/************************************************step3:  Init SYS and common VB*************************************************/hi_memset(&stVbConf, sizeof(VB_CONFIG_S), 0, sizeof(VB_CONFIG_S));stVbConf.u32MaxPoolCnt              = 2;u32BlkSize = COMMON_GetPicBufferSize(stSize.u32Width, stSize.u32Height, SAMPLE_PIXEL_FORMAT, DATA_BITWIDTH_10, COMPRESS_MODE_SEG, DEFAULT_ALIGN);stVbConf.astCommPool[0].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[0].u32BlkCnt   = 10;u32BlkSize = VI_GetRawBufferSize(stSize.u32Width, stSize.u32Height, PIXEL_FORMAT_RGB_BAYER_16BPP, COMPRESS_MODE_NONE, DEFAULT_ALIGN);stVbConf.astCommPool[1].u64BlkSize  = u32BlkSize;stVbConf.astCommPool[1].u32BlkCnt   = 4;s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("system init failed with %d!\n", s32Ret);goto EXIT;}s32Ret = SAMPLE_COMM_VI_SetParam(&stViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_SetParam failed with %d!\n", s32Ret);goto EXIT;}/************************************************step 4: start VI*************************************************/s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VI_StartVi failed with %d!\n", s32Ret);goto EXIT3;}/************************************************step 5: start VPSS, need one grp*************************************************/stVpssGrpAttr.u32MaxW                        = stSize.u32Width;stVpssGrpAttr.u32MaxH                        = stSize.u32Height;stVpssGrpAttr.enPixelFormat                  = enPixFormat;stVpssGrpAttr.enDynamicRange                 = enDynamicRange;stVpssGrpAttr.stFrameRate.s32SrcFrameRate    = -1;stVpssGrpAttr.stFrameRate.s32DstFrameRate    = -1;HI_S32 i;for(i = 0; i < VPSS_MAX_PHY_CHN_NUM; i++){abChnEnable[i]                               = HI_TRUE;stVpssChnAttr[i].u32Width                    = stSize.u32Width;stVpssChnAttr[i].u32Height                   = stSize.u32Height;stVpssChnAttr[i].enChnMode                   = VPSS_CHN_MODE_USER;stVpssChnAttr[i].enCompressMode              = enCompressMode;stVpssChnAttr[i].enDynamicRange              = enDynamicRange;stVpssChnAttr[i].enPixelFormat               = enPixFormat;stVpssChnAttr[i].enVideoFormat               = enVideoFormat;stVpssChnAttr[i].stFrameRate.s32SrcFrameRate = -1;stVpssChnAttr[i].stFrameRate.s32DstFrameRate = -1;stVpssChnAttr[i].u32Depth                    = 1;stVpssChnAttr[i].bMirror                     = HI_FALSE;stVpssChnAttr[i].bFlip                       = HI_FALSE;stVpssChnAttr[i].stAspectRatio.enMode        = ASPECT_RATIO_NONE;}/***********************************************Crop裁剪************************************************/VPSS_CROP_INFO_S stCropInfo;stCropInfo.bEnable = HI_TRUE;stCropInfo.enCropCoordinate = VPSS_CROP_ABS_COOR; //绝对坐标模式stCropInfo.stCropRect.s32X = 0;stCropInfo.stCropRect.s32Y = 0;stCropInfo.stCropRect.u32Width = 1000;stCropInfo.stCropRect.u32Height = 1000;/***********************************************旋转************************************************/ROTATION_E enRotation = ROTATION_90;s32Ret = MY_SAMPLE_COMM_VPSS_Start(VpssGrp0, abChnEnable, &stVpssGrpAttr, stVpssChnAttr, &stCropInfo, enRotation);//s32Ret = SAMPLE_COMM_VPSS_Start(VpssGrp0, abChnEnable, &stVpssGrpAttr, stVpssChnAttr);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Start Grp0 failed with %d!\n", s32Ret);goto EXIT2;}/************************************************step 6:  VI bind VPSS, for total parallel, no need bind*************************************************//************************************************step 7:  start V0*************************************************/SAMPLE_COMM_VO_GetDefConfig(&stVoConfig);stVoConfig.VoDev                                    = VoDev;stVoConfig.enVoIntfType                             = enVoIntfType;stVoConfig.enIntfSync                               = g_enIntfSync;stVoConfig.enPicSize                                = enPicSize;stVoConfig.u32DisBufLen                             = g_u32DisBufLen;stVoConfig.enDstDynamicRange                        = enDynamicRange;stVoConfig.enVoMode                                 = VO_MODE_1MUX;s32Ret = MY_SAMPLE_COMM_VO_StartVO(&stVoConfig);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VO_StartVO failed with %d!\n", s32Ret);goto EXIT1;}/************************************************step 8:  VO bind VPSS*************************************************/s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[0], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The original image now displayed, press any key to view the cropped image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[0], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The cropped image now displayed, press any key to view the rotated image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[2], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The rotated image now displayed, press any key to view the zoomed image\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[2], stVoConfig.VoDev, VoChn);s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp0, VpssChn[3], stVoConfig.VoDev, VoChn);if (HI_SUCCESS != s32Ret){SAMPLE_PRT("SAMPLE_COMM_VPSS_Bind_VO Grp0 failed with %d!\n", s32Ret);goto EXIT1;}printf("The zoomed image now displayed, press any key to stop\n");getchar();SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[3], stVoConfig.VoDev, VoChn);// PAUSE();// SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp0, VpssChn[1], stVoConfig.VoDev, VoChn);
EXIT1:SAMPLE_COMM_VO_StopVO(&stVoConfig);
EXIT2:SAMPLE_COMM_VPSS_Stop(VpssGrp0, abChnEnable);
EXIT3:SAMPLE_COMM_VI_StopVi(&stViConfig);
EXIT:SAMPLE_COMM_SYS_Exit();return s32Ret;
}/******************************************************************************
* function    : main()
* Description : main
******************************************************************************/
int main(int argc, char* argv[])
{HI_S32 s32Ret = HI_FAILURE;VO_INTF_TYPE_E enVoIntfType = VO_INTF_HDMI; //输出格式signal(SIGINT, SAMPLE_VIO_HandleSig);signal(SIGTERM, SAMPLE_VIO_HandleSig);s32Ret = MY_SAMPLE_VIPO(enVoIntfType);if (HI_SUCCESS == s32Ret){SAMPLE_PRT("my_vipo exit success!\n");}else{SAMPLE_PRT("my_vipo exit abnormally!\n");}return s32Ret;
}

图像处理结果(旋转90度+缩放):
在这里插入图片描述

终端运行输出结果:
在这里插入图片描述


总结

海思的mpp/sample还是很实用的。。。。(。-_-。)

  • 关于缩放:如果只用vpss缩放,vo输出图像会自动适应显示器的大小;
  • 关于缩放:vo设置显示的分辨率才能让显示变成对应的分辨率;

这篇关于Hi3559 MPP学习记录(2)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/382382

相关文章

Oracle查询优化之高效实现仅查询前10条记录的方法与实践

《Oracle查询优化之高效实现仅查询前10条记录的方法与实践》:本文主要介绍Oracle查询优化之高效实现仅查询前10条记录的相关资料,包括使用ROWNUM、ROW_NUMBER()函数、FET... 目录1. 使用 ROWNUM 查询2. 使用 ROW_NUMBER() 函数3. 使用 FETCH FI

Python MySQL如何通过Binlog获取变更记录恢复数据

《PythonMySQL如何通过Binlog获取变更记录恢复数据》本文介绍了如何使用Python和pymysqlreplication库通过MySQL的二进制日志(Binlog)获取数据库的变更记录... 目录python mysql通过Binlog获取变更记录恢复数据1.安装pymysqlreplicat

Servlet中配置和使用过滤器的步骤记录

《Servlet中配置和使用过滤器的步骤记录》:本文主要介绍在Servlet中配置和使用过滤器的方法,包括创建过滤器类、配置过滤器以及在Web应用中使用过滤器等步骤,文中通过代码介绍的非常详细,需... 目录创建过滤器类配置过滤器使用过滤器总结在Servlet中配置和使用过滤器主要包括创建过滤器类、配置过滤

正则表达式高级应用与性能优化记录

《正则表达式高级应用与性能优化记录》本文介绍了正则表达式的高级应用和性能优化技巧,包括文本拆分、合并、XML/HTML解析、数据分析、以及性能优化方法,通过这些技巧,可以更高效地利用正则表达式进行复杂... 目录第6章:正则表达式的高级应用6.1 模式匹配与文本处理6.1.1 文本拆分6.1.2 文本合并6

python与QT联合的详细步骤记录

《python与QT联合的详细步骤记录》:本文主要介绍python与QT联合的详细步骤,文章还展示了如何在Python中调用QT的.ui文件来实现GUI界面,并介绍了多窗口的应用,文中通过代码介绍... 目录一、文章简介二、安装pyqt5三、GUI页面设计四、python的使用python文件创建pytho

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]