mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Enable FaceRecognizer on OpenCV3
This commit is contained in:
parent
d7b7161871
commit
2405bc5a59
@ -1,15 +1,19 @@
|
|||||||
#include "FaceRecognizer.h"
|
|
||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
|
|
||||||
#if CV_MAJOR_VERSION >= 3
|
#ifdef HAVE_OPENCV_FACE
|
||||||
#warning TODO: port me to OpenCV 3
|
#include "FaceRecognizer.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
|
|
||||||
|
|
||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
|
||||||
|
#if CV_MAJOR_VERSION >= 3
|
||||||
|
namespace cv {
|
||||||
|
using std::vector;
|
||||||
|
using cv::face::createEigenFaceRecognizer;
|
||||||
|
using cv::face::createFisherFaceRecognizer;
|
||||||
|
using cv::face::createLBPHFaceRecognizer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define EIGEN 0
|
#define EIGEN 0
|
||||||
#define LBPH 1
|
#define LBPH 1
|
||||||
#define FISHER 2
|
#define FISHER 2
|
||||||
@ -373,7 +377,27 @@ NAN_METHOD(FaceRecognizerWrap::GetMat) {
|
|||||||
JSTHROW("getMat takes a key")
|
JSTHROW("getMat takes a key")
|
||||||
}
|
}
|
||||||
std::string key = std::string(*Nan::Utf8String(info[0]->ToString()));
|
std::string key = std::string(*Nan::Utf8String(info[0]->ToString()));
|
||||||
cv::Mat m = self->rec->getMat(key);
|
cv::Mat m;
|
||||||
|
#if CV_MAJOR_VERSION >= 3
|
||||||
|
cv::face::BasicFaceRecognizer *bfr =
|
||||||
|
dynamic_cast<cv::face::BasicFaceRecognizer*>(self->rec.get());
|
||||||
|
if (bfr == NULL) {
|
||||||
|
Nan::ThrowTypeError("getMat not supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (key.compare("mean") == 0) {
|
||||||
|
m = bfr->getMean();
|
||||||
|
} else if (key.compare("eigenvectors") == 0) {
|
||||||
|
m = bfr->getEigenVectors();
|
||||||
|
} else if (key.compare("eigenvalues") == 0) {
|
||||||
|
m = bfr->getEigenValues();
|
||||||
|
} else {
|
||||||
|
Nan::ThrowTypeError("Unknown getMat keyname");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
m = self->rec->getMat(key);
|
||||||
|
#endif
|
||||||
|
|
||||||
Local<Object> im = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
Local<Object> im = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im);
|
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(im);
|
||||||
|
|||||||
@ -1,8 +1,15 @@
|
|||||||
#include "OpenCV.h"
|
#include "OpenCV.h"
|
||||||
|
|
||||||
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
|
#ifdef HAVE_OPENCV_FACE
|
||||||
|
|
||||||
|
#if CV_MAJOR_VERSION >= 3
|
||||||
|
#include <opencv2/face.hpp>
|
||||||
|
namespace cv {
|
||||||
|
using cv::face::FaceRecognizer;
|
||||||
|
}
|
||||||
|
#else
|
||||||
#include "opencv2/contrib/contrib.hpp"
|
#include "opencv2/contrib/contrib.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
class FaceRecognizerWrap: public Nan::ObjectWrap {
|
class FaceRecognizerWrap: public Nan::ObjectWrap {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -22,7 +22,12 @@
|
|||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/videoio.hpp>
|
#include <opencv2/videoio.hpp>
|
||||||
|
#include <opencv2/opencv_modules.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
|
||||||
|
#define HAVE_OPENCV_FACE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <nan.h>
|
#include <nan.h>
|
||||||
|
|
||||||
|
|||||||
@ -38,11 +38,11 @@ extern "C" void init(Local<Object> target) {
|
|||||||
BackgroundSubtractorWrap::Init(target);
|
BackgroundSubtractorWrap::Init(target);
|
||||||
Features::Init(target);
|
Features::Init(target);
|
||||||
LDAWrap::Init(target);
|
LDAWrap::Init(target);
|
||||||
#if CV_SUBMINOR_VERSION>=4
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_OPENCV_FACE
|
||||||
FaceRecognizerWrap::Init(target);
|
FaceRecognizerWrap::Init(target);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NODE_MODULE(opencv, init)
|
NODE_MODULE(opencv, init)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user