I've installed OpenCV 2.2 and now I can't get webcam capture to work. It worked ok in 2.1. OpenCV detects a webcam, doesn't report any errors or warnings, but each frame is a gray image. I even tried a code sample from OpenCV wiki:
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
//GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
//Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
Did anyone run into this issue? I'm using 64bit Win7 and Visual Studio 2010.
I found the solution after a very long search.
The problem is that if doesn't have a delay between showing the frames happen this problem.
The solution is put
cvWaitKey(20);
in loop.I had the same problem. I figured that it might be the settings on my camera, because I was supposed to have an input of 640x480px (which I could not adjust) and I could not adjust the permissions for the feed. So I installed a virtual webcam, which pretty much resolved both issues. I got an input dialogue, chose the virtual camera and it worked. I managed to set it to 640x480 in the app too.
My virtual camera was called ManyCam, but it looks like it is made for teenage girls, wanted me to install 3 other apps and I'm still not sure weather it doesn't come with 'complementary' trojans.
However, it lets you adjust colors, hue, contrast etc. and other stuff you might need for testing.
Try this:
You might try a look at this post as well.
To put it simple, changing
from
to
worked for me. See also the post here.
Here is the Solution.
Every image frame captured is being converted into grayscale image in the first line below. Commenting and running the code alone will show an error since since you are not capturing any processed image into the edges frame, which is being displayed in imshow.
Hence comment the
cvtColor
line and change the second parameter inimshow
toframe
. This will allow you to display the colour video from the webcam.I am using cvtColor and found that
cvtColor(image,image,CV_BGR2RGB);
didn't work.But the good news is that this change work !!
Also include:
and in the .pro file the library: