Ask Your Question
0

how to release camera when application is running

asked 2013-07-06 06:00:17 -0600

updated 2013-07-06 17:12:43 -0600

I thought when i==20 it will release the camera but the process is still holding the camera. How can I release it. I am sure cvQueryFrame is playing some role for not releasing the camera.

main( int argc, char* argv[] ) {
    int i=1;
    CvCapture* capture = NULL;
    capture = cvCreateCameraCapture( 0 );

    IplImage *frames = cvQueryFrame(capture);

    while(1) {      
        if (i==20)
            cvReleaseCapture ( &capture );

        char c = cvWaitKey(33);
        if( c == 27 ) break;
        i++;
    }
    return 0;

}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-07-06 17:50:29 -0600

There is many issues in your program. First, your are not querying frame in the loop, which seems suspicious. Second, your are not displaying the picture in the loop. And third, you releasing the camera capture, but on what window are you wanting the key pressed? I suggest:

int main( int argc, char* argv[] ) {
    int i=1;
    CvCapture* capture = NULL;
    capture = cvCreateCameraCapture( 0 );

    IplImage *frames = NULL;

    while(1) {
        frames = cvQueryFrame(capture);
        // Here you should test if the frames are well grabbed.
        if (i==20)
        {
            cvReleaseCapture ( &capture );
            break; // because the previous cvQueryFrame will failed otherwise.
        }

        cvShowImage( "Camera", frames );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
        i++;
    }
    return 0;

}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-06 06:00:17 -0600

Seen: 437 times

Last updated: Jul 06 '13