如何获取相机的分辨率

How to get resolution of camera

本文关键字:相机 分辨率 获取 何获取      更新时间:2023-10-16
  1. 如何获得相机的分辨率?有人可以给我一些建议。
  2. 我只能做以下内容,但是要获得解决方案需要太多时间。
  3. 代码的顺序看起来像这样: apen camerra B.改变相机的分辨率,然后检查REUSLT

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

    }

不幸的是,没有方便的方法可以通过OpenCV API获得特定相机的支持分辨率列表(因为它支持了许多平台和许多视频捕获后端)。即使您的代码也会遭受此困扰,请阅读videoio.hpp的来源。但是,大多数数字视频设备都支持标准分辨率,您可以简单地从中选择。获取支持格式的实际列表的另一种方法是使用第三方库,因为实例QT通过几个呼叫解决了此任务。