Ask Your Question

Revision history [back]

//This is just a version of opencv that treats differently the waitKey function. So the answer is to change it fro cvWaitKey. // check this out, as y'all can notice I am just continuously taking pictures from the webcam and stoping as soon as the user presses anykey.

Mat frame;

VideoCapture cap(0);

// check if we succeeded
if (!cap.isOpened()) {
    cerr << "ERROR! Unable to open camera\n";
    return -1;
}

for (;;)
{
    //  storing the camera capture into 'frame'
    cap>>frame;
    // check if we succeeded
    if (frame.empty()) {
        cerr << "ERROR! \n";
        break;
    }
    // show live and wait for a key with timeout long enough to show images
    imshow("Live", frame);
    if (cvWaitKey(30) >= 0)
        break;
}  
return 0;