VideoCapture.read

asked 2019-07-10 09:33:44 -0600

updated 2019-07-11 22:51:06 -0600

supra56 gravatar image

Hello everybody,

I have a problem with my soft but I don't know where the bug is. The purpose is only open the camera on my laptop then print every frame. I can open the camera but when I read with VideoCapture.read method, the output image seems to be "empty" because when I use imshow, it print a black image on the screen..

I tried to delay after initialization but it wasn't better.

Have you ever had the same problem ? Otherwise, do you have an idea ?

For information, I'm using Windows 10

The code is very simple:

int main(int argc, char** argv)
{

        Mat image;
        VideoCapture capture;

        capture.open(0);
        if(capture.isOpened())
        {
            capture.set(CAP_PROP_FPS, 30);
            printf("Capture is open. fps = %f\n", capture.get(CAP_PROP_FPS));
            namedWindow("Cam", WINDOW_AUTOSIZE);
            while(true){
                capture.read(image);
                imshow("Cam", image);
                if(image.empty()){
                    cout << "empty!" << endl;
                }else{
                    cout << "image OK -> " << mean(image) << endl;
                }
                if(waitKey(10) == 27) break;
            }
        }

        return 0;
}

Thank you for reading me and for your help :)

edit retag flag offensive close merge delete