Ask Your Question

Revision history [back]

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;

}