Skip to content
Browse files

Initial work on face recognition using the FaceRecognizer class from …

…opencv 2.4.4
  • Loading branch information...
1 parent ebd1f6e commit b17fceca72176afa596743055d495d185abd34c7 @peterbraden committed Mar 13, 2013
Showing with 93 additions and 2 deletions.
  1. +1 −0 binding.gyp
  2. +6 −1 smoke/smoketest.js
  3. +52 −0 src/FaceRecognizer.cc
  4. +28 −0 src/FaceRecognizer.h
  5. +6 −1 src/init.cc
View
1 binding.gyp
@@ -11,6 +11,7 @@
, "src/VideoCaptureWrap.cc"
, "src/CamShift.cc"
, "src/HighGUI.cc"
+ , "src/FaceRecognizer.cc"
]
, 'libraries': [
'<!@(pkg-config --libs opencv)'
View
7 smoke/smoketest.js
@@ -1,5 +1,10 @@
var cv = require('../lib/opencv')
+
+
+var facerec = new cv.FaceRecognizer();
+
+/*
var win = new cv.NamedWindow("foo");
cv.readImage('./examples/stuff.png', function(e, im){
im.pyrDown();
@@ -8,7 +13,7 @@ cv.readImage('./examples/stuff.png', function(e, im){
win.destroy();
})
-
+*/
/*
View
52 src/FaceRecognizer.cc
@@ -0,0 +1,52 @@
+#include "FaceRecognizer.h"
+#include "OpenCV.h"
+
+#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
+
+#include "Matrix.h"
+
+void AsyncPredict(uv_work_t *req);
+void AfterAsyncPredict(uv_work_t *req);
+
+Persistent<FunctionTemplate> FaceRecognizerWrap::constructor;
+
+void
+FaceRecognizerWrap::Init(Handle<Object> target) {
+ HandleScope scope;
+
+ // Constructor
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(FaceRecognizerWrap::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("FaceRecognizer"));
+
+ NODE_SET_PROTOTYPE_METHOD(constructor, "train", Train);
+
+
+ target->Set(String::NewSymbol("FaceRecognizer"), constructor->GetFunction());
+};
+
+Handle<Value>
+FaceRecognizerWrap::New(const Arguments &args) {
+ HandleScope scope;
+
+ if (args.This()->InternalFieldCount() == 0)
+ return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
+
+
+ // By default initialize eigenface
+ cv::FaceRecognizer *f = cv::createEigenFaceRecognizer();
+ FaceRecognizerWrap *pt = new FaceRecognizerWrap(f);
+
+ pt->Wrap(args.This());
+ return args.This();
+}
+
+FaceRecognizerWrap::FaceRecognizerWrap(cv::FaceRecognizer* f){
+}
+
+Handle<Value>
+FaceRecognizerWrap::Train(const Arguments& args){
+ SETUP_FUNCTION(Matrix)
+
+}
+#endif // End version > 2.4
View
28 src/FaceRecognizer.h
@@ -0,0 +1,28 @@
+#include "OpenCV.h"
+
+#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
+
+#include "opencv2/contrib/contrib.hpp"
+
+class FaceRecognizerWrap: public node::ObjectWrap {
+ public:
+ cv::FaceRecognizer* rec;
+
+ static Persistent<FunctionTemplate> constructor;
+ static void Init(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ FaceRecognizerWrap(cv::FaceRecognizer* f);
+
+ JSFUNC(Train)
+ JSFUNC(Update)
+
+ JSFUNC(Predict)
+ static void EIO_Predict(eio_req *req);
+ static int EIO_AfterPredict(eio_req *req);
+
+};
+
+
+
+#endif
View
7 src/init.cc
@@ -6,6 +6,7 @@
#include "Contours.h"
#include "CamShift.h"
#include "HighGUI.h"
+#include "FaceRecognizer.h"
extern "C" void
@@ -18,8 +19,12 @@ init(Handle<Object> target) {
VideoCaptureWrap::Init(target);
Contour::Init(target);
TrackedObject::Init(target);
-
NamedWindow::Init(target);
+
+ #if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
+ FaceRecognizerWrap::Init(target);
+ #endif
+
};
NODE_MODULE(opencv, init)

0 comments on commit b17fcec

Please sign in to comment.
Something went wrong with that request. Please try again.