开启VI视频输入设备 范例
文档示例:
/********************************* *函数功能:开启VI设备 *输出参数: *返回值:成功为0 失败非0 *********************************/ HI_S32 enable_VI() { HI_S32 s32Ret; //返回值 VI_DEV ViDev = 0; //VI设备号 VI_CHN ViChn = 0; //VI通道号 VI_DEV_ATTR_S stDevAttr; //视频输入设备的属性 VI_CHN_ATTR_S stChnAttr; /*配置视频输入设备的属性*/ stDevAttr.enIntfMode =VI_MODE_BT1120_STANDARD; //接口模式 stDevAttr.enWorkMode = VI_WORK_MODE_1Multiplex; //124路复合工作模式 stDevAttr.au32CompMask[0] = 0xFF000000; //分量掩码 stDevAttr.au32CompMask[1] = 0xFF0000; stDevAttr. enClkEdge = VI_CLK_EDGE_SINGLE_UP; //时钟边沿采样模式 stDevAttr.s32AdChnId[0] = -1; //取值范围 stDevAttr.s32AdChnId[1] = -1; stDevAttr.s32AdChnId[2] = -1; stDevAttr.s32AdChnId[3] = -1; s32Ret = HI_MPI_VI_SetDevAttr(ViDev, &stDevAttr); //设置VI设备属性 if (s32Ret != HI_SUCCESS) { printf("Set dev attributes failed with error code %#x!\n", s32Ret); return HI_FAILURE; } s32Ret = HI_MPI_VI_EnableDev(ViDev); //使能VI设备 if (s32Ret != HI_SUCCESS) { printf("Enable dev failed with error code %#x!\n", s32Ret); return HI_FAILURE; } /*配置VI通道属性*/ stChnAttr.stCapRest.s32X = 0; //捕获区域起始坐标 stChnAttr.stCapRect.s32Y = 0; stChnAttr.stCapRect.u32Width = 1920; //捕获区域宽高 stChnAttr.stCapRect.u32Height = 1080; stChnAttr.stDestSize.u32Width = 1920; //目标图像大小 stChnAttr.stDestSize.u32Height = 1080; stChnAttr.enCapSel = VI_CAPSEL_BOTH; //帧场选择 stChnAttr.enScanMode = VI_SCAN_PROGRESSIVE; //输入扫描模式 隔行or逐行 stChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_422; //像素储存格式 stChnAttr.bMirror = HI_FALSE; //是否水平翻转 stChnAttr.bFlip = HI_FALSE; //是否垂直翻转 stChnAttr.s32SrcFrameRate = -1; //原始帧率 stChnAttr.s32DstFrameRate = -1; //目标帧率 s32Ret = HI_MPI_VI_SetChnAttr(ViChn,&stChnAttr); if (s32Ret != HI_SUCCESS) { printf("Set chn attributes failed with error code %#x!\n", s32Ret); return HI_FAILURE; } s32Ret = HI_MPI_VI_EnableChn(ViChn); //使能VI通道 if (s32Ret != HI_SUCCESS) { printf("Enable chn failed with error code %#x!\n", s32Ret); return HI_FAILURE; } /* now, vi is capturing images, you can do something else ... */ s32Ret = HI_MPI_VI_DisableChn(ViChn); //关闭通道 if (s32Ret != HI_SUCCESS) { printf("Disable chn failed with error code %#x!\n", s32Ret); return HI_FAILURE; } s32Ret = HI_MPI_VI_DisableDev(ViDev); //关闭设备 if (s32Ret != HI_SUCCESS) { printf("Disable dev failed with error code %#x!\n", s32Ret); return HI_FAILURE; } }