简体   繁体   中英

cvQueryFrame() returns grey frames

cvQueryFrame() returns grey frames UNLESS I put a put a breakpoint at cvQueryFrame(capture) . The program just needs to hit the breakpoint once and then afterwards I get proper frames from the camera. I've tried delays, dummy frames, combination of the two but it just doesn't seem to work without that breakpoint.

cvNamedWindow("video", CV_WINDOW_AUTOSIZE);
CvCapture *capture  = cvCaptureFromCAM(1);
if (capture == NULL)
{
    return -1;
}

Mat frame;
for(int i = 0;i<10;i++)
{
    frame = cvQueryFrame(capture);
}


while(1)
{
    try
    {
    frame = cvQueryFrame(capture);
    imshow("video", frame);
    char c = cvWaitKey(1);
    if(c == 33)
        break;
    }

    catch(Exception e)
    {
        break;
    }
}
cvReleaseCapture( &capture);
cvDestroyWindow( "video" );

return 0;

You can try setting your cvWaitKey value to 5 or 10? The camera needs time to deliver the next frame and draw the previous one. Using the waitKey allows the openCV the time to draw the image to the screen. It is possible that you are now grabbing frames correctly, but that you are unable to show them properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM