Merge pull request #589 from thielsn/opencv_3_3_support_v2

Opencv 3 3 support v2
This commit is contained in:
btsimonh 2017-11-14 13:14:35 +00:00 committed by GitHub
commit 1a5947c934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 11 deletions

View File

@ -5,7 +5,15 @@
#include "Matrix.h" #include "Matrix.h"
#include <nan.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 { namespace cv {
using std::vector; using std::vector;
using cv::face::EigenFaceRecognizer; using cv::face::EigenFaceRecognizer;
@ -68,7 +76,11 @@ NAN_METHOD(FaceRecognizerWrap::New) {
} }
// By default initialize LBPH // 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); 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); FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
pt->Wrap(info.This()); pt->Wrap(info.This());
@ -91,8 +103,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateLBPH) {
DOUBLE_FROM_ARGS(threshold, 4) DOUBLE_FROM_ARGS(threshold, 4)
Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();
cv::Ptr<cv::FaceRecognizer> f = cv::LBPHFaceRecognizer::create(radius, #if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
neighbors, grid_x, grid_y, threshold); 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); FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH);
pt->Wrap(n); pt->Wrap(n);
@ -109,8 +124,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateEigen) {
DOUBLE_FROM_ARGS(threshold, 1) DOUBLE_FROM_ARGS(threshold, 1)
Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();
cv::Ptr<cv::FaceRecognizer> f = cv::EigenFaceRecognizer::create(components, #if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
threshold); 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); FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, EIGEN);
pt->Wrap(n); pt->Wrap(n);
@ -127,9 +145,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateFisher) {
DOUBLE_FROM_ARGS(threshold, 1) DOUBLE_FROM_ARGS(threshold, 1)
Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); Local<Object> n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked();
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
cv::Ptr<cv::FaceRecognizer> f = cv::FisherFaceRecognizer::create(components, cv::Ptr<cv::FaceRecognizer> f = cv::FisherFaceRecognizer::create(components, threshold);
threshold); #else
cv::Ptr<cv::FaceRecognizer> f = cv::createFisherFaceRecognizer(components, threshold);
#endif
FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER); FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER);
pt->Wrap(n); pt->Wrap(n);
@ -378,7 +398,11 @@ NAN_METHOD(FaceRecognizerWrap::SaveSync) {
JSTHROW("Save takes a filename") JSTHROW("Save takes a filename")
} }
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString())); std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
self->rec->write(filename); self->rec->write(filename);
#else
self->rec->save(filename);
#endif
return; return;
} }
@ -388,7 +412,11 @@ NAN_METHOD(FaceRecognizerWrap::LoadSync) {
JSTHROW("Load takes a filename") JSTHROW("Load takes a filename")
} }
std::string filename = std::string(*Nan::Utf8String(info[0]->ToString())); std::string filename = std::string(*Nan::Utf8String(info[0]->ToString()));
#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3
self->rec->read(filename); self->rec->read(filename);
#else
self->rec->load(filename);
#endif
return; return;
} }

View File

@ -19,6 +19,7 @@ void NamedWindow::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "show", Show); Nan::SetPrototypeMethod(ctor, "show", Show);
Nan::SetPrototypeMethod(ctor, "destroy", Destroy); Nan::SetPrototypeMethod(ctor, "destroy", Destroy);
Nan::SetPrototypeMethod(ctor, "blockingWaitKey", BlockingWaitKey); Nan::SetPrototypeMethod(ctor, "blockingWaitKey", BlockingWaitKey);
Nan::SetPrototypeMethod(ctor, "resizeWindow", ResizeWindow);
target->Set(Nan::New("NamedWindow").ToLocalChecked(), ctor->GetFunction()); target->Set(Nan::New("NamedWindow").ToLocalChecked(), ctor->GetFunction());
}; };
@ -34,7 +35,8 @@ NAN_METHOD(NamedWindow::New) {
if (info.Length() == 1) { if (info.Length() == 1) {
win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0); win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0);
} else { //if (info.Length() == 2){ } else { //if (info.Length() == 2){
win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0); win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())),
info[1]->IntegerValue());
} }
win->Wrap(info.Holder()); win->Wrap(info.Holder());
@ -68,8 +70,6 @@ NAN_METHOD(NamedWindow::Destroy) {
} }
NAN_METHOD(NamedWindow::BlockingWaitKey) { NAN_METHOD(NamedWindow::BlockingWaitKey) {
Nan::HandleScope scope;
//SETUP_FUNCTION(NamedWindow)
int time = 0; int time = 0;
if (info.Length() > 1) { if (info.Length() > 1) {
@ -85,4 +85,16 @@ NAN_METHOD(NamedWindow::BlockingWaitKey) {
info.GetReturnValue().Set(Nan::New<Number>(res)); info.GetReturnValue().Set(Nan::New<Number>(res));
} }
NAN_METHOD(NamedWindow::ResizeWindow) {
SETUP_FUNCTION(NamedWindow)
if (info.Length() != 2) {
throw "expected 2 argurments: width, height";
}//otherwise
int width = info[0]->IntegerValue();
int height = info[1]->IntegerValue();
cv::resizeWindow(self->winname, width, height);
}
#endif #endif

View File

@ -16,6 +16,7 @@ public:
JSFUNC(Show) JSFUNC(Show)
;JSFUNC(Destroy) ;JSFUNC(Destroy)
;JSFUNC(BlockingWaitKey) ;JSFUNC(BlockingWaitKey)
;JSFUNC(ResizeWindow)
; ;
}; };