Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Constructors for other algorithms

  • Loading branch information...
commit 0efbd11d0c74e4a587c9540da4c12fb2a59ebce3 1 parent b8ce5d0
@peterbraden authored
View
53 smoke/smoketest.js
@@ -8,55 +8,18 @@ for (var i = 1; i< 41; i++){
}
}
-var facerec = new cv.FaceRecognizer();
-facerec.train(trainingData);
+cv.readImage("/Users/peterbraden/Downloads/orl_faces/s6/10.pgm", function(e, im){
-console.log(facerec.predictSync('/Users/peterbraden/Downloads/orl_faces/s6/10.pgm'));
+ var facerec = cv.FaceRecognizer.createFisherFaceRecognizer();
+ facerec.train(trainingData);
+ console.log(facerec.predictSync(im));
-/*
-var win = new cv.NamedWindow("foo");
-cv.readImage('./examples/stuff.png', function(e, im){
- im.pyrDown();
- win.show(im);
- console.log(win.blockingWaitKey(0), "!!")
- win.destroy();
-
-})
-*/
-
-
-/*
-new cv.VideoCapture(0).read(function(mat){
-
- mat.resize(200,100)
- mat.save('./out.jpg')
-
- mat.detectObject("./data/haarcascade_frontalface_alt.xml", {min : [30,30]}, function(err, faces){
- for (var i=0;i<faces.length; i++){
- var x = faces[i]
- mat.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
- }
- console.log(faces.length ? (faces.length + " faces found") : "No faces")
- mat.save('./out.jpg');
-
- })
+ var x = new cv.NamedWindow("out")
+ x.show(im);
+ x.blockingWaitKey();
+ x.destroy()
})
-cv.readImage("./examples/stuff.png", function(err, im){
- var i2 = im.copy()
- i2.convertGrayscale()
- i2.canny(5, 300)
- var features = i2.houghLinesP();
- for (var i=0;i<features.length; i++){
- var x = features[i]
- im.line([x[0], x[1]], [x[2], x[3]]);
- im.ellipse(x[0], x[1]);
- im.ellipse(x[2], x[3]);
- }
- console.log(features)
- im.save('./out.jpg');
-});
-*/
View
78 src/FaceRecognizer.cc
@@ -34,13 +34,17 @@ FaceRecognizerWrap::Init(Handle<Object> target) {
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(FaceRecognizerWrap::New));
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("FaceRecognizer"));
-
+
+ NODE_SET_METHOD(constructor, "createLBPHFaceRecognizer", CreateLBPH);
+ NODE_SET_METHOD(constructor, "createEigenFaceRecognizer", CreateEigen);
+ NODE_SET_METHOD(constructor, "createFisherFaceRecognizer", CreateFisher);
+
NODE_SET_PROTOTYPE_METHOD(constructor, "train", Train);
NODE_SET_PROTOTYPE_METHOD(constructor, "predictSync", PredictSync);
target->Set(String::NewSymbol("FaceRecognizer"), constructor->GetFunction());
-};
+};
Handle<Value>
FaceRecognizerWrap::New(const Arguments &args) {
@@ -57,6 +61,76 @@ FaceRecognizerWrap::New(const Arguments &args) {
return args.This();
}
+Handle<Value>
+FaceRecognizerWrap::CreateLBPH(const Arguments &args) {
+ HandleScope scope;
+
+ int radius = 1;
+ int neighbors = 8;
+ int grid_x = 8;
+ int grid_y = 8;
+ double threshold = 80;
+
+ INT_FROM_ARGS(radius, 0)
+ INT_FROM_ARGS(neighbors, 1)
+ INT_FROM_ARGS(grid_x, 2)
+ INT_FROM_ARGS(grid_y, 3)
+ DOUBLE_FROM_ARGS(threshold, 4)
+
+ Local<Object> n = FaceRecognizerWrap::constructor->GetFunction()->NewInstance();
+
+ cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(
+ radius, neighbors, grid_x, grid_y, threshold
+ );
+ FaceRecognizerWrap *pt = new FaceRecognizerWrap(f);
+
+ pt->Wrap(n);
+ return n;
+}
+
+Handle<Value>
+FaceRecognizerWrap::CreateEigen(const Arguments &args) {
+ HandleScope scope;
+
+ int components = 0;
+ double threshold = DBL_MAX;
+
+ INT_FROM_ARGS(components, 0)
+ DOUBLE_FROM_ARGS(threshold, 1)
+
+ Local<Object> n = FaceRecognizerWrap::constructor->GetFunction()->NewInstance();
+
+ cv::Ptr<cv::FaceRecognizer> f = cv::createEigenFaceRecognizer(
+ components, threshold
+ );
+ FaceRecognizerWrap *pt = new FaceRecognizerWrap(f);
+
+ pt->Wrap(n);
+ return n;
+}
+
+Handle<Value>
+FaceRecognizerWrap::CreateFisher(const Arguments &args) {
+ HandleScope scope;
+
+ int components = 0;
+ double threshold = DBL_MAX;
+
+ INT_FROM_ARGS(components, 0)
+ DOUBLE_FROM_ARGS(threshold, 1)
+
+ Local<Object> n = FaceRecognizerWrap::constructor->GetFunction()->NewInstance();
+
+ cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(
+ components, threshold
+ );
+ FaceRecognizerWrap *pt = new FaceRecognizerWrap(f);
+
+ pt->Wrap(n);
+ return n;
+}
+
+
FaceRecognizerWrap::FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f){
rec = f;
}
View
4 src/FaceRecognizer.h
@@ -14,6 +14,10 @@ class FaceRecognizerWrap: public node::ObjectWrap {
FaceRecognizerWrap(cv::Ptr<cv::FaceRecognizer> f);
+ JSFUNC(CreateLBPH)
+ JSFUNC(CreateEigen)
+ JSFUNC(CreateFisher)
+
JSFUNC(Train)
JSFUNC(Update)
View
11 src/OpenCV.h
@@ -33,6 +33,17 @@ using namespace node;
#define JSTHROW(ERR) \
return v8::ThrowException(v8::Exception::Error(v8::String::New(ERR)));
+
+#define INT_FROM_ARGS(NAME, IND) \
+ if (args[IND]->IsInt32()){ \
+ NAME = args[IND]->Uint32Value(); \
+ }
+
+#define DOUBLE_FROM_ARGS(NAME, IND) \
+ if (args[IND]->IsInt32()){ \
+ NAME = args[IND]->NumberValue(); \
+ }
+
class OpenCV: public node::ObjectWrap{
public:
static void Init(Handle<Object> target);
Please sign in to comment.
Something went wrong with that request. Please try again.