I\'m using Visual Studio Express 2013 with OpenCV 2.4.7
, following this tutorial.
I have spent hours searching the web for solutions, including all of t
I tried your code and for me it works (it visualizes the current webcam input)!
I ran it on Visual Studio 2012 Ultimate with OpenCV 2.4.7.
...
The error occurs because the image is empty, so try this:
while (true) {
cap >> image;
if(!image.empty()){
imshow("window", image);
}
// delay 33ms
waitKey(33);
}
Maybe the first image you receive from your webcam is empty. In this case imshow will not throw an error. So hopefully the next input images are not empty.
Do this:
VideoCapture cap;
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
int camOpen = cap.open(CV_CAP_ANY);
Or you can try changing this:
while (true) {
cap >> image;
imshow("window", image);
// delay 33ms
waitKey(33);
}
to
try
{
cap >> image;
imshow("window", image);
waitKey(33);
}
catch (Exception& e)
{
const char* err_msg = e.what();
std::cout << "exception caught: imshow:\n" << err_msg << std::endl;
}
int i=0;
while(i<4)
{
VideoCapture cap(0); // force camera to open 4 tiMEs
i++;
}
waitKey(5000);
VideoCapture cap(0);
int camOpen = cap.open(CV_CAP_ANY);
namedWindow("window", CV_WINDOW_AUTOSIZE);
while (true) {
cap >> image;
imshow("window", image);
waitKey(33);
}
Do this it will work for you for sure.