Permalink
Browse files

Basic version of Face recognition working

  • Loading branch information...
1 parent 64f933f commit 053a693c9a456b2faeebdd34f27698be2142e82f @peterbraden committed Mar 14, 2013
Showing with 35 additions and 15 deletions.
  1. +8 −4 smoke/smoketest.js
  2. +27 −11 src/FaceRecognizer.cc
View
@@ -1,13 +1,17 @@
var cv = require('../lib/opencv')
+var trainingData = []
+for (var i = 1; i< 41; i++){
+ for (var j = 1; j<10; j++){
+ trainingData.push([i,"/Users/peterbraden/Downloads/orl_faces/s" + i + "/" + j + ".pgm" ])
+ }
+}
var facerec = new cv.FaceRecognizer();
-facerec.train([
- [0, '/Users/peterbraden/Downloads/orl_faces/s1/1.pgm']
- , [0, '/Users/peterbraden/Downloads/orl_faces/s1/2.pgm']
-])
+facerec.train(trainingData);
+console.log(facerec.predictSync('/Users/peterbraden/Downloads/orl_faces/s1/10.pgm'));
/*
View
@@ -5,6 +5,22 @@
#include "Matrix.h"
+
+// Todo, move somewhere useful
+cv::Mat fromMatrixOrFilename(Local<Value> v){
+ cv::Mat im;
+ if (v->IsString()){
+ std::string filename = std::string(*v8::String::AsciiValue(v->ToString()));
+ im = cv::imread(filename);
+ //std::cout<< im.size();
+ } else {
+ Matrix *img = ObjectWrap::Unwrap<Matrix>(v->ToObject());
+ im = img->mat;
+ }
+ return im;
+}
+
+
void AsyncPredict(uv_work_t *req);
void AfterAsyncPredict(uv_work_t *req);
@@ -73,14 +89,7 @@ FaceRecognizerWrap::Train(const Arguments& args){
}
int label = valarr->Get(0)->Uint32Value();
- cv::Mat im;
- if (valarr->Get(1)->IsString()){
- std::string filename = std::string(*v8::String::AsciiValue(valarr->Get(1)->ToString()));
- im = cv::imread(filename);
- } else {
- Matrix *img = ObjectWrap::Unwrap<Matrix>(valarr->Get(1)->ToObject());
- im = img->mat;
- }
+ cv::Mat im = fromMatrixOrFilename(valarr->Get(1));
labels.push_back(label);
images.push_back(im);
}
@@ -94,9 +103,16 @@ FaceRecognizerWrap::Train(const Arguments& args){
Handle<Value>
FaceRecognizerWrap::PredictSync(const Arguments& args){
SETUP_FUNCTION(FaceRecognizerWrap)
-
+
+ cv::Mat im = fromMatrixOrFilename(args[0]);//TODO CHECK!
+ cv::cvtColor(im, im, CV_RGB2GRAY);
+ // int predictedLabel = self->rec->predict(im);
+
+ int predictedLabel = -1;
+ double confidence = 0.0;
+ self->rec->predict(im, predictedLabel, confidence);
+// std::cout << confidence;
+ return scope.Close(Number::New(predictedLabel));
}
-
-
#endif // End version > 2.4

0 comments on commit 053a693

Please sign in to comment.