# include
#include
using namespace std;
Using the namespace CV;
Int main () {
VideoCapture cap (0);//open the default camera
if(! Cap. IsOpened ()) {
return -1;
}
Mat frame;
Mat edges;
Mat gray;
CascadeClassifier cascade;
Bool stop=false;
Cascade. The load (" haarcascade_frontalface_alt. XML ");
PtrModelPCA=createEigenFaceRecognizer ();
ModelPCA - & gt; Load (" MyFacePCAModel. XML ");
while(! Stop)
{
Cap> Frame;
vectorFaces (0);
CvtColor (frame, gray, CV_BGR2GRAY);
EqualizeHist (gray, gray);//histogram average change
Cascade. DetectMultiScale (gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size (30, 30));
Mat face;
Point text_lb;
For (size_t I=0; i{
If (faces [I] height> 0 & amp; & Faces [I] width> 0)
{
Face=gray (faces [I]);
Text_lb=Point (faces [I] x, faces [I] y);
A rectangle (frame, faces [I], Scalar (0, 255), 1,8,0);
}
}
Mat face_test;
Int predictPCA=0;
If (face. Rows>
=120){
The resize (face, face_test, Size (92112));
}
if(! Face_test. Empty ())
{
PredictPCA=modelPCA - & gt; Predict (face_test);
}
coutIf (predictPCA==35)
{
String name="shijunye";
PutText (frame, name, text_lb FONT_HERSHEY_COMPLEX, 1, Scalar,0,255 (0));
}
Imshow (" face ", the frame);
If (waitKey (50) & gt;=0)
Stop=true;
}
return 0;
}
This is all my code, and run without error, but finally out of the picture:
To know a great god can tell the problem,
Thank you in advance,
CodePudding user response:
Suggest the original poster to compile first link debug OpenCV bring relevant example code,CodePudding user response:
You can use other software to open the camera, to see if the camera was installed correctly, such as QQ is okCodePudding user response:
From the point of the effect of this operation, you open the code of cameras is carried out, you can also verify, in the if (! Cap. IsOpened () {return - 1; } here change return 1 to you can directly see the phenomena such as the output of one line of what, to judge the camera exactly have opened, if the camera opened but the result is still so will consider whether your camera problem,CodePudding user response:
Some notebook open cameras have to dial a small DIP switch,