Skip to content

Instantly share code, notes, and snippets.

@jimregan
Created September 16, 2013 13:10
Show Gist options
  • Save jimregan/6580503 to your computer and use it in GitHub Desktop.
Save jimregan/6580503 to your computer and use it in GitHub Desktop.
Another adaptation, to run on a saved model. Supposed to filter false positives from the detector, the first model (638 positive, 638 negative) run gave 20/34 wrong :( (Plus, the model is 128M, so I'm not in a hurry to include it)
/*
* Copyright (c) 2011. Philipp Wagner <bytefish[at]gmx[dot]de>.
* Released to public domain under terms of the BSD Simplified license.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the organization nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* See <http://www.opensource.org/licenses/bsd-license>
*/
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "facerec.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
static void read_file(const string& filename, vector<string>& todo) {
std::ifstream file(filename.c_str(), ifstream::in);
if (!file) {
string error_message = "No valid input file was given, please check the given filename.";
CV_Error(CV_StsBadArg, error_message);
}
string line;
while (getline(file, line)) {
todo.push_back(line);
}
}
int main(int argc, const char *argv[]) {
if (argc != 2) {
cout << "usage: " << argv[0] << " <csv.ext>" << endl;
exit(1);
}
string fn = string(argv[1]);
vector<string> todo;
try {
read_file(fn, todo);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn << "\". Reason: " << e.msg << endl;
exit(1);
}
Ptr<FaceRecognizer> model = createLBPHFaceRecognizer();
model->load("posneg.yml");
for(vector<string>::iterator it = todo.begin(); it != todo.end(); it++) {
Mat current = imread(*it, 0);
int predictedLabel = model->predict(current);
if(predictedLabel == 0)
cout << *it << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment