Skip to content

Commit

Permalink
Cleaned the PersonRecognizer class.
Browse files Browse the repository at this point in the history
Need to add some documentation to classes and functions.
  • Loading branch information
EyalAr committed Mar 18, 2013
1 parent 5fea287 commit e13b930
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
20 changes: 9 additions & 11 deletions PersonRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

#include "PersonRecognizer.h"

PersonRecognizer::PersonRecognizer(const vector<Mat> &imgs) {
//all images are faces of the same person, so the same label for all.
PersonRecognizer::PersonRecognizer(const vector<Mat> &imgs, int radius, int neighbors,
int grid_x, int grid_y, double threshold) {
//all images are faces of the same person, so initialize the same label for all.
vector<int> labels(imgs.size());
for (vector<int>::iterator it = labels.begin() ; it != labels.end() ; *(it++) = PERSON_LABEL_A);
//labels[0] = PERSON_LABEL_B;
//create and train the model:
//_model = createFisherFaceRecognizer(0,5.0);
//_model = createEigenFaceRecognizer(0,4900.0);
_model = createLBPHFaceRecognizer(3,8,8,8,180);
_model->train(imgs, labels);
for (vector<int>::iterator it = labels.begin() ; it != labels.end() ; *(it++) = PERSON_LABEL);
_faceSize = Size(imgs[0].size().width, imgs[0].size().height);

//build recognizer model:
_model = createLBPHFaceRecognizer(radius, neighbors, grid_x, grid_y, threshold);
_model->train(imgs, labels);
}

PersonRecognizer::~PersonRecognizer() {}
Expand All @@ -26,6 +25,5 @@ bool PersonRecognizer::recognize(const Mat &face, double &confidence) const {
cvtColor(face, gray, CV_BGR2GRAY);
resize(gray, gray, _faceSize);
_model->predict(gray, label, confidence);
//return label == PERSON_LABEL ? confidence : 0;
return label == PERSON_LABEL_A || label == PERSON_LABEL_B ? true : false;
return label == PERSON_LABEL ? true : false;
}
6 changes: 3 additions & 3 deletions PersonRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#ifndef PERSONRECOGNIZER_H
#define PERSONRECOGNIZER_H

#define PERSON_LABEL_A 10
#define PERSON_LABEL_B 11
#define PERSON_LABEL 10 //some arbitrary label

#include <string>
#include "cv.hpp"
Expand All @@ -19,7 +18,8 @@ using namespace cv;

class PersonRecognizer {
public:
PersonRecognizer(const vector<Mat> &imgs);
PersonRecognizer(const vector<Mat> &imgs, int radius, int neighbors,
int grid_x, int grid_y, double threshold);
virtual ~PersonRecognizer();
bool recognize(const Mat &face, double &confidence) const;
private:
Expand Down
15 changes: 11 additions & 4 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/** Inputs: **/
#define CASCADE_PATH "cascades/haarcascade_frontalface_default.xml"
#define IN_VID "C:/Users/Eyal/Downloads/031213_POTUS_ExportCouncil_HD.mp4"
#define IN_VID "input_vid/031213_POTUS_ExportCouncil_HD.mp4"
#define TRAINING_LIST "obama_faces/list"

/** Input video: **/
Expand All @@ -37,18 +37,25 @@
#define LINE_TYPE CV_AA
#define FONT FONT_HERSHEY_PLAIN
#define FONT_COLOR Scalar(255,255,255)
#define THICKNESS_TITLE 2
#define THICKNESS_TITLE 1.9
#define SCALE_TITLE 1.9
#define POS_TITLE cvPoint(10, 30)
#define THICKNESS_LINK 1.6
#define SCALE_LINK 1.3
#define POS_LINK cvPoint(10, 55)

/** Face detector: **/
#define DET_SCALE_FACTOR 1.01
#define DET_MIN_NEIGHBORS 40
#define DET_SCALE_FACTOR 1.01
#define DET_MIN_NEIGHBORS 40
#define DET_MIN_SIZE_RATIO 0.06
#define DET_MAX_SIZE_RATIO 0.18

/** LBPH face recognizer: **/
#define LBPH_RADIUS 3
#define LBPH_NEIGHBORS 8
#define LBPH_GRID_X 8
#define LBPH_GRID_Y 8
#define LBPH_THRESHOLD 180.0

#endif /* DEFS_H */

2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char** argv) {

read_training_set(string(TRAINING_LIST), training_set);

PersonRecognizer pr(training_set);
PersonRecognizer pr(training_set, LBPH_RADIUS, LBPH_NEIGHBORS, LBPH_GRID_X, LBPH_GRID_Y, LBPH_THRESHOLD);

/**********************/

Expand Down

0 comments on commit e13b930

Please sign in to comment.