1. 程式人生 > 實用技巧 >開啟VI視訊輸入裝置 範例

開啟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; } }