Ask Your Question

Revision history [back]

could you try the code below

#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main( int argc, char** argv )
{
    int empty_frame_count = 0;
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        if(frame.empty())
        {
            empty_frame_count ++;
            if(empty_frame_count > 20) break;
            frame = Mat::zeros(480,640,CV_8UC3);
            waitKey(100);
        }

        imshow("VideoCapture", frame);
        if(waitKey(30) >= 0) break;

    }
    return 0;
}

could you try the code below

#include "opencv2/highgui/highgui.hpp"
 #include "iostream"
using namespace cv;

int main( int argc, char** argv )
{
    std::cout << getBuildInformation();
    int empty_frame_count = 0;
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        if(frame.empty())
        {
            empty_frame_count ++;
            if(empty_frame_count > 20) break;
            frame = Mat::zeros(480,640,CV_8UC3);
            waitKey(100);
        }

        imshow("VideoCapture", frame);
        if(waitKey(30) >= 0) break;

    }
    return 0;
}