Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

[OpenCV]How to get the resolution of camera

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;

}

}