1
votes

I'm using OpenCV 2.2 on Visual C++ 2010 Express on Windows 7 64 bit. Whenever I try running some simple program to access and display the images from the webcam, I get a black output window instead of the actual webcam feed. OpenCV detects a webcam, doesn't report any errors or warnings, but each frame is a blacked out image.

This is the code I've been trying on:

#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
    Mat img;
    VideoCapture cap(0);
    while (true)
    {
        cap >> img;
        Mat edges;
        cvtColor(img, edges, CV_BGR2GRAY);
        Canny(edges, edges, 30, 60);
        imshow("window label", img);
        waitKey(100);
    }
    return 0;
}

Any idea on what seems to be the problem? Everything was working fine on OpenCV 2.4.2, but I had to switch since I could not get MSER to work properly.

1
Hi, i tested your code as it is and it is working fine, i did not find any problem....I am sure that there is no problem from opencv.. just try with another web cam...mostly it should work ....G453

1 Answers

1
votes

try using VideoCapture cap(-1)

this will automatically select the webcam device. It might or might not solve the problem, but worth a try.