mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Initial work on face recognition using the FaceRecognizer class from opencv 2.4.4
This commit is contained in:
parent
ebd1f6e4e8
commit
b17fceca72
@ -11,6 +11,7 @@
|
|||||||
, "src/VideoCaptureWrap.cc"
|
, "src/VideoCaptureWrap.cc"
|
||||||
, "src/CamShift.cc"
|
, "src/CamShift.cc"
|
||||||
, "src/HighGUI.cc"
|
, "src/HighGUI.cc"
|
||||||
|
, "src/FaceRecognizer.cc"
|
||||||
]
|
]
|
||||||
, 'libraries': [
|
, 'libraries': [
|
||||||
'<!@(pkg-config --libs opencv)'
|
'<!@(pkg-config --libs opencv)'
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
var cv = require('../lib/opencv')
|
var cv = require('../lib/opencv')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var facerec = new cv.FaceRecognizer();
|
||||||
|
|
||||||
|
/*
|
||||||
var win = new cv.NamedWindow("foo");
|
var win = new cv.NamedWindow("foo");
|
||||||
cv.readImage('./examples/stuff.png', function(e, im){
|
cv.readImage('./examples/stuff.png', function(e, im){
|
||||||
im.pyrDown();
|
im.pyrDown();
|
||||||
@ -8,7 +13,7 @@ cv.readImage('./examples/stuff.png', function(e, im){
|
|||||||
win.destroy();
|
win.destroy();
|
||||||
|
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
52
src/FaceRecognizer.cc
Normal file
52
src/FaceRecognizer.cc
Normal file
@ -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
|
||||||
28
src/FaceRecognizer.h
Normal file
28
src/FaceRecognizer.h
Normal file
@ -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
|
||||||
@ -6,6 +6,7 @@
|
|||||||
#include "Contours.h"
|
#include "Contours.h"
|
||||||
#include "CamShift.h"
|
#include "CamShift.h"
|
||||||
#include "HighGUI.h"
|
#include "HighGUI.h"
|
||||||
|
#include "FaceRecognizer.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
@ -18,8 +19,12 @@ init(Handle<Object> target) {
|
|||||||
VideoCaptureWrap::Init(target);
|
VideoCaptureWrap::Init(target);
|
||||||
Contour::Init(target);
|
Contour::Init(target);
|
||||||
TrackedObject::Init(target);
|
TrackedObject::Init(target);
|
||||||
|
|
||||||
NamedWindow::Init(target);
|
NamedWindow::Init(target);
|
||||||
|
|
||||||
|
#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
|
||||||
|
FaceRecognizerWrap::Init(target);
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NODE_MODULE(opencv, init)
|
NODE_MODULE(opencv, init)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user