Ask Your Question
0

WebCam not working

asked 2017-05-05 12:08:57 -0600

Hi. I am trying to run this simple code and it is not working but it used to. I am using version 2.4.9 in Code::Blocks.

image description

I have also tried using Visual C++ but the problem is the same. The VideoCapture object is returning an empty frame. This is not only the case with the first frame, but also every other. As I said, this used to work but for some strange reason now it does not. It still works on Linux Mint 13.7.

Any ideas what could be causing the problem?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-05-05 12:58:58 -0600

updated 2017-05-05 16:53:35 -0600

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;
}
edit flag offensive delete link more

Comments

The program shows a black image for some time and then it ends.

Mirza94 gravatar imageMirza94 ( 2017-05-05 13:20:30 -0600 )edit

i edited the code . what is your output for getBuildInformation()

sturkmen gravatar imagesturkmen ( 2017-05-05 16:54:47 -0600 )edit
Mirza94 gravatar imageMirza94 ( 2017-05-06 05:49:28 -0600 )edit

i think you should try an updated version of OpenCV

sturkmen gravatar imagesturkmen ( 2017-05-06 08:36:01 -0600 )edit

I tried 2.4.11. Same problem.

Mirza94 gravatar imageMirza94 ( 2017-05-06 10:25:40 -0600 )edit
0

answered 2017-05-08 16:01:45 -0600

I have the same problem as you. Dumb trick to work on Ubuntu (sorry, no idea about Windows), uninstall OpenCV and install the default: sudo apt-get libopencv-dev. But I am trying to figure out why version (2.4.13) does not open the webcam, 3.2 works fine, I must be forgetting some flag or setting....

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-05 12:08:57 -0600

Seen: 2,260 times

Last updated: May 08 '17