Write OpenCV program, turn on the camera, behold the program error on the book, can open the camera, but can't capture the image
I tried it with my brother's computer, it worked, no problem.
On the internet for a long time, tried a lot of methods, no use, and later in a Baidu know to find a way to success
http://zhidao.baidu.com/link?url=8I5s8NuD3uID9-8oAYb2uFf-thH6j-i940Tgil9XPpYqwB7olGEEsKg3I3Jm4pPdTnVz1q__ Ivkxaz42vvtfpr_3geqhv1c-idzz_y33aum
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace CV;
using namespace std;
String Name= "my";
int main ()
{
videocapture capture;//declare video read-in class
Capture.open (0);//read in video from the camera 0 means read from the camera
if (! Capture.isopened ())///first to determine whether to turn on
the camera {
cout<< "can not open";
Cin.get ();
return-1;
}
Namedwindow (name);
while (1) {
mat cap;//define a mat variable to store the image of each frame
capture>>cap;//Read the current frame
if (!cap.empty ())// Determines whether the current frame captures success * * This step is important
imshow (name, CAP);//If the current frame captures successfully, the
else
cout<< "Can not" is displayed;
Waitkey (30); Delay 30 milliseconds
}
return 0;
}
I don't know if you guys saw it.
can not means that the program does not read the image
That's why I went wrong, the first frame of the camera can't be read in .
The most important problem is solved, but there is a small problem, the window name appears garbled,
The problem hasn't been solved yet.
I'll fix it later and put it up.