Skip to content

Commit

Permalink
FIX OpenCV 3.3: support compilation with OpenCV 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Thiel committed Nov 13, 2017
1 parent ece9efc commit 6597046
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/FaceRecognizer.cc
Expand Up @@ -5,7 +5,15 @@
#include "Matrix.h"
#include <nan.h>

#if CV_MAJOR_VERSION >= 3
#if CV_MAJOR_VERSION < 3
#elif CV_MINOR_VERSION < 3
namespace cv {
using std::vector;
using cv::face::createEigenFaceRecognizer;
using cv::face::createFisherFaceRecognizer;
using cv::face::createLBPHFaceRecognizer;
}
#else // version 3.3 and higher
namespace cv {
using std::vector;
using cv::face::EigenFaceRecognizer;
Expand Down Expand Up @@ -68,7 +76,11 @@ NAN_METHOD(FaceRecognizerWrap::New) {
}

// By default initialize LBPH
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
cv::Ptr<cv::FaceRecognizer> f = cv::LBPHFaceRecognizer::create(1, 8, 8, 8, 80.0);
#else
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0);
#endif
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);

pt->Wrap(info.This());
Expand All @@ -91,8 +103,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateLBPH) {
DOUBLE_FROM_ARGS(threshold, 4)

Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();
cv::Ptr<cv::FaceRecognizer> f = cv::LBPHFaceRecognizer::create(radius,
neighbors, grid_x, grid_y, threshold);
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
cv::Ptr<cv::FaceRecognizer> f = cv::LBPHFaceRecognizer::create(radius, neighbors, grid_x, grid_y, threshold);
#else
cv::Ptr<cv::FaceRecognizer> f = cv::createLBPHFaceRecognizer(radius, neighbors, grid_x, grid_y, threshold);
#endif
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
pt->Wrap(n);

Expand All @@ -109,8 +124,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateEigen) {
DOUBLE_FROM_ARGS(threshold, 1)

Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();
cv::Ptr<cv::FaceRecognizer> f = cv::EigenFaceRecognizer::create(components,
threshold);
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
cv::Ptr<cv::FaceRecognizer> f = cv::EigenFaceRecognizer::create(components, threshold);
#else
cv::Ptr<cv::FaceRecognizer> f = cv::createEigenFaceRecognizer(components, threshold);
#endif
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, EIGEN);
pt->Wrap(n);

Expand All @@ -127,9 +145,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateFisher) {
DOUBLE_FROM_ARGS(threshold, 1)

Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();

cv::Ptr<cv::FaceRecognizer> f = cv::FisherFaceRecognizer::create(components,
threshold);
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
cv::Ptr<cv::FaceRecognizer> f = cv::FisherFaceRecognizer::create(components, threshold);
#else
cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(components, threshold);
#endif
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER);
pt->Wrap(n);

Expand Down Expand Up @@ -378,7 +398,11 @@ NAN_METHOD(FaceRecognizerWrap::SaveSync) {
JSTHROW("Save takes a filename")
}
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
self->rec->write(filename);
#else
self->rec->save(filename);
#endif
return;
}

Expand All @@ -388,7 +412,11 @@ NAN_METHOD(FaceRecognizerWrap::LoadSync) {
JSTHROW("Load takes a filename")
}
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
self->rec->read(filename);
#else
self->rec->load(filename);
#endif
return;
}

Expand Down

0 comments on commit 6597046

Please sign in to comment.