如何获得相机的分辨率

时间:2016-12-09 03:00:28

标签: c++ opencv camera

  1. 如何获得相机的分辨率?有人可以给我一些建议。
  2. 我只能做以下事情,但需要花费太多时间才能获得解决方案。
  3. 代码的序列如下所示:  a。打开camerra  b。更改相机的分辨率,然后检查重新打印

    void GetResolution( const int& countOfCamera, resolution_t (&resoulationTemp)[MAX_RESOLUTION] ){
    VideoCapture *pVideoCaptures[MAX_CAMERA] = {NULL};
    bool ret1 = false;
    bool ret2 = false;
    
    for ( int j=0; j<countOfCamera; ++j ) {
        pVideoCaptures[j] = new VideoCapture(j);
    
        /*==========================================================================
        *If we don't do this, we will not open the Camera correctly
        ===========================================================================*/
        pVideoCaptures[j]->set( CV_CAP_PROP_FRAME_WIDTH, defaultResolution.width );
        pVideoCaptures[j]->set ( CV_CAP_PROP_FRAME_HEIGHT, defaultResolution.height );
    }
    
    for ( int i=0; i<MAX_RESOLUTION; ++i ) {
    
        for ( int j=0; j<countOfCamera; ++j ) {
            ret1 = pVideoCaptures[j]->set( CV_CAP_PROP_FRAME_WIDTH, resolutions[i].width );
            ret2 = pVideoCaptures[j]->set ( CV_CAP_PROP_FRAME_HEIGHT, resolutions[i].height );
    
            if ( !(ret1 && ret2) ) {                                //The resolution is not OK
                break;      //Check the next resolution
            } else if ( j == ( countOfCamera -1 ) ) {               //The resolution is OK for all camera,then store it.
                resoulationTemp[i].width = resolutions[i].width;
                resoulationTemp[i].height = resolutions[i].height;
            } else {
                //Do nothing
            }
        }
    
    }
    
    for ( int j=0; j<countOfCamera; ++j )                           //Release the memory
    {
        pVideoCaptures[j]->release();
    
        delete pVideoCaptures[j];
        pVideoCaptures[j] = NULL;
    
    }
    

    }

1 个答案:

答案 0 :(得分:0)

不幸的是,没有方便的方法可以通过opencv API获取特定摄像机支持的分辨率列表(因为它支持如此多的平台和如此多的视频捕获后端)。即使您的代码也会受此影响,请阅读videoio.hpp的来源。但大多数数字视频设备都支持标准分辨率,您只需从中选择即可。获得支持格式的实际列表的另一种方法是使用第三方库,对于实例Qt通过几个调用来解决此任务。