Home > Back-end >  Consult VS2015 error c3646 "CV_OVERRIDE" unknown rewrite specifiers, etc
Consult VS2015 error c3646 "CV_OVERRIDE" unknown rewrite specifiers, etc

Time:03-19


Procedure is as follows:
#include
#include
#include
#include

Using the namespace CV;
Using the namespace CV: : face;
using namespace std;

Int main (int arg c, char * * argv) {
The string filename=string (" C:/face photograph/image/myfaces/list. CSV ");
Ifstream file (filename. C_str (), ifstream: : in);
if (! The file) {
Printf (" could not load the file correctly... \n");
return -1;
}

The string line, path, classlabel;
Vector Images;
Vector Labels.
Char separator='; ';
While (getline (file, line)) {
Stringstream liness (line);
Getline (liness, path, the separator);
Getline (liness, classlabel);
if (! Path. The empty () & amp; & ! Classlabel. Empty ()) {
Path://printf (" % s \ n ", path. The c_str ());
Images. The push_back (imread (path, 0));
Labels. The push_back (atoi (classlabel c_str ()));
}
}

If (images. The size () & lt; 1 | | labels. The size () & lt; 1) {
Printf (" invalid image path... \n");
return -1;
}

Int height=images [0]. Rows;
Int width=images [0]. Cols;
Height: printf (" % d, width: % d \ n ", height, width);

Mat testSample=images [images. The size () - 1);
Int testLabel=labels [labels. The size () - 1);
Images. Pop_back ();
Labels. Pop_back ();

//train it
Ptr The model=createEigenFaceRecognizer ();
The model - & gt; "Train" (images, labels);

//recognition face
Int predictedLabel=model - & gt; Predict (the testSample);
Printf (" actual label: % d, predict the label: % d \ n ", testLabel, predictedLabel);

Mat eigenvalues=model - & gt; GetEigenValues ();
Mat W=model - & gt; GetEigenVectors ();
Mat mean=model - & gt; GetMean ();
Mat meanFace=mean. Reshape (1, height);
Mat DST.
If (meanFace channels ()==1) {
The normalize (meanFace, DST, 0, 255, NORM_MINMAX, CV_8UC1);
}
Else if (meanFace channels ()==3) {
The normalize (meanFace, DST, 0, 255, NORM_MINMAX, CV_8UC3);
}
Imshow (Mean "Face", DST);

//show eigen faces
for (int i=0; I & lt; Min (10, W.c ols); I++) {
Mat ev=W.c ol (I). The clone ();
Mat grayscale.
Mat eigenFace=ev. Reshape (1, height);
If (eigenFace. Channels ()==1) {
The normalize (eigenFace, grayscale, 0, 255, NORM_MINMAX, CV_8UC1);
}
Else if (eigenFace. Channels ()==3) {
The normalize (eigenFace, grayscale, 0, 255, NORM_MINMAX, CV_8UC3);
}
Mat colorface;
ApplyColorMap (grayscale, colorface COLORMAP_JET);
Char * winTitle=new char [128].
Sprintf (winTitle, "eigenface_ % d", I);
Imshow (winTitle colorface);
}

//rebuild face
For (int num=min (10, W.c ols); Num & lt; Min (W.c ols, 300); Num +=15) {
Mat evs=Mat (W, Range: all (), the Range (0, num));
Mat the projection=LDA: : subspaceProject (evs, scheme, images [0]. Reshape (1, 1));
Mat reconstruction=LDA: : subspaceReconstruct (evs, scheme, the projection).

Mat result=reconstruction. Reshape (1, height);
If (result. Channels ()==1) {
Normalize (result, reconstruction, 0, 255, NORM_MINMAX, CV_8UC1);
}
Else if (result. Channels ()==3) {
Normalize (result, reconstruction, 0, 255, NORM_MINMAX, CV_8UC3);
}
Char * winTitle=new char [128].
Sprintf (winTitle, "recon_face_ % d", num);
Imshow (winTitle, reconstruction);
}

WaitKey (0);
return 0;
}