Ask Your Question
0

[OpenCV]How to get the resolution of camera

asked 2016-12-08 20:38:37 -0600

Jack_Wellem gravatar image

How to get the resolution of camera?Can somebody give me some suggestion. Only i can do is the following,but it takes too much time to get the resolution.

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;

}

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-09 05:31:49 -0600

pi-null-mezon gravatar image

Unfortunately there is no convenient way to get supported resolutions list for the particular camera by the opencv API (as it supports so many platforms and so many video capturing backends). Even your code will suffer from this, read the sources of videoio.hpp. But most of the digital video devices supports standard resolutions, you can simply select from them. Another way to get actual list of supported formats is to use 3rd party libraries, for the instance Qt solves this task by the couple of calls.

edit flag offensive delete link more

Comments

I think this is a good idea to solve this question.Thank you.

Jack_Wellem gravatar imageJack_Wellem ( 2016-12-09 19:19:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-08 20:38:37 -0600

Seen: 4,991 times

Last updated: Dec 09 '16