Commit 084ca5d7 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

fixed facerec_demo compile errors

parent cd0569a3
...@@ -18,11 +18,14 @@ ...@@ -18,11 +18,14 @@
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/face.hpp" #include "opencv2/face.hpp"
#include "opencv2/core/utility.hpp"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <map>
using namespace cv; using namespace cv;
using namespace cv::face; using namespace cv::face;
...@@ -30,7 +33,7 @@ using namespace std; ...@@ -30,7 +33,7 @@ using namespace std;
static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, std::map<int, string>& labelsInfo, char separator = ';') { static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, std::map<int, string>& labelsInfo, char separator = ';') {
ifstream csv(filename.c_str()); ifstream csv(filename.c_str());
if (!csv) CV_Error(CV_StsBadArg, "No valid input file was given, please check the given filename."); if (!csv) CV_Error(Error::StsBadArg, "No valid input file was given, please check the given filename.");
string line, path, classlabel, info; string line, path, classlabel, info;
while (getline(csv, line)) { while (getline(csv, line)) {
stringstream liness(line); stringstream liness(line);
...@@ -49,7 +52,7 @@ static void read_csv(const string& filename, vector<Mat>& images, vector<int>& l ...@@ -49,7 +52,7 @@ static void read_csv(const string& filename, vector<Mat>& images, vector<int>& l
glob(root, files, true); glob(root, files, true);
for(vector<String>::const_iterator f = files.begin(); f != files.end(); ++f) { for(vector<String>::const_iterator f = files.begin(); f != files.end(); ++f) {
cout << "\t" << *f << endl; cout << "\t" << *f << endl;
Mat img = imread(*f, CV_LOAD_IMAGE_GRAYSCALE); Mat img = imread(*f, IMREAD_GRAYSCALE);
static int w=-1, h=-1; static int w=-1, h=-1;
static bool showSmallSizeWarning = true; static bool showSmallSizeWarning = true;
if(w>0 && h>0 && (w!=img.cols || h!=img.rows)) cout << "\t* Warning: images should be of the same size!" << endl; if(w>0 && h>0 && (w!=img.cols || h!=img.rows)) cout << "\t* Warning: images should be of the same size!" << endl;
...@@ -99,7 +102,7 @@ int main(int argc, const char *argv[]) { ...@@ -99,7 +102,7 @@ int main(int argc, const char *argv[]) {
// Quit if there are not enough images for this demo. // Quit if there are not enough images for this demo.
if(images.size() <= 1) { if(images.size() <= 1) {
string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!"; string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!";
CV_Error(CV_StsError, error_message); CV_Error(Error::StsError, error_message);
} }
// The following lines simply get the last images from // The following lines simply get the last images from
// your dataset and remove it from the vector. This is // your dataset and remove it from the vector. This is
...@@ -107,7 +110,8 @@ int main(int argc, const char *argv[]) { ...@@ -107,7 +110,8 @@ int main(int argc, const char *argv[]) {
// cv::FaceRecognizer on) and the test data we test // cv::FaceRecognizer on) and the test data we test
// the model with, do not overlap. // the model with, do not overlap.
Mat testSample = images[images.size() - 1]; Mat testSample = images[images.size() - 1];
int testLabel = labels[labels.size() - 1]; int nlabels = (int)labels.size();
int testLabel = labels[nlabels-1];
images.pop_back(); images.pop_back();
labels.pop_back(); labels.pop_back();
// The following lines create an Eigenfaces model for // The following lines create an Eigenfaces model for
...@@ -125,7 +129,8 @@ int main(int argc, const char *argv[]) { ...@@ -125,7 +129,8 @@ int main(int argc, const char *argv[]) {
// cv::createEigenFaceRecognizer(10, 123.0); // cv::createEigenFaceRecognizer(10, 123.0);
// //
Ptr<FaceRecognizer> model = createEigenFaceRecognizer(); Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->setLabelsInfo(labelsInfo); for( int i = 0; i < nlabels; i++ )
model->setLabelInfo(i, labelsInfo[i]);
model->train(images, labels); model->train(images, labels);
string saveModelPath = "face-rec-model.txt"; string saveModelPath = "face-rec-model.txt";
cout << "Saving the trained model to " << saveModelPath << endl; cout << "Saving the trained model to " << saveModelPath << endl;
......
...@@ -45,20 +45,10 @@ ...@@ -45,20 +45,10 @@
#include "opencv2/face.hpp" #include "opencv2/face.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"
#include <map> #include <map>
#include <valarray>
namespace cv
{
// special function to get pointer to constant valarray elements, since
// simple &arr[0] does not compile on VS2005/VS2008.
template<typename T> inline const T* get_data(const std::valarray<T>& arr)
{ return &((std::valarray<T>&)arr)[0]; }
}
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment