diff --git a/src/FaceRecognizer.cc b/src/FaceRecognizer.cc index 3393aed..47b5583 100644 --- a/src/FaceRecognizer.cc +++ b/src/FaceRecognizer.cc @@ -5,7 +5,15 @@ #include "Matrix.h" #include -#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; @@ -68,7 +76,11 @@ NAN_METHOD(FaceRecognizerWrap::New) { } // By default initialize LBPH +#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3 cv::Ptr f = cv::LBPHFaceRecognizer::create(1, 8, 8, 8, 80.0); +#else + cv::Ptr f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0); +#endif FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH); pt->Wrap(info.This()); @@ -91,8 +103,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateLBPH) { DOUBLE_FROM_ARGS(threshold, 4) Local n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); - cv::Ptr f = cv::LBPHFaceRecognizer::create(radius, - neighbors, grid_x, grid_y, threshold); +#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3 + cv::Ptr f = cv::LBPHFaceRecognizer::create(radius, neighbors, grid_x, grid_y, threshold); +#else + cv::Ptr f = cv::createLBPHFaceRecognizer(radius, neighbors, grid_x, grid_y, threshold); +#endif FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, LBPH); pt->Wrap(n); @@ -109,8 +124,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateEigen) { DOUBLE_FROM_ARGS(threshold, 1) Local n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); - cv::Ptr f = cv::EigenFaceRecognizer::create(components, - threshold); +#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3 + cv::Ptr f = cv::EigenFaceRecognizer::create(components, threshold); +#else + cv::Ptr f = cv::createEigenFaceRecognizer(components, threshold); +#endif FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, EIGEN); pt->Wrap(n); @@ -127,9 +145,11 @@ NAN_METHOD(FaceRecognizerWrap::CreateFisher) { DOUBLE_FROM_ARGS(threshold, 1) Local n = Nan::NewInstance(Nan::GetFunction(Nan::New(FaceRecognizerWrap::constructor)).ToLocalChecked()).ToLocalChecked(); - - cv::Ptr f = cv::FisherFaceRecognizer::create(components, - threshold); +#if CV_MAJOR_VERSION >= 3 && CV_MINOR_VERSION >= 3 + cv::Ptr f = cv::FisherFaceRecognizer::create(components, threshold); +#else + cv::Ptr f = cv::createFisherFaceRecognizer(components, threshold); +#endif FaceRecognizerWrap *pt = new FaceRecognizerWrap(f, FISHER); pt->Wrap(n); @@ -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; } @@ -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; } diff --git a/src/HighGUI.cc b/src/HighGUI.cc index 139fe94..4126c69 100644 --- a/src/HighGUI.cc +++ b/src/HighGUI.cc @@ -19,6 +19,7 @@ void NamedWindow::Init(Local target) { Nan::SetPrototypeMethod(ctor, "show", Show); Nan::SetPrototypeMethod(ctor, "destroy", Destroy); Nan::SetPrototypeMethod(ctor, "blockingWaitKey", BlockingWaitKey); + Nan::SetPrototypeMethod(ctor, "resizeWindow", ResizeWindow); target->Set(Nan::New("NamedWindow").ToLocalChecked(), ctor->GetFunction()); }; @@ -34,7 +35,8 @@ NAN_METHOD(NamedWindow::New) { if (info.Length() == 1) { win = new NamedWindow(std::string(*Nan::Utf8String(info[0]->ToString())), 0); } 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()); @@ -68,8 +70,6 @@ NAN_METHOD(NamedWindow::Destroy) { } NAN_METHOD(NamedWindow::BlockingWaitKey) { - Nan::HandleScope scope; - //SETUP_FUNCTION(NamedWindow) int time = 0; if (info.Length() > 1) { @@ -85,4 +85,16 @@ NAN_METHOD(NamedWindow::BlockingWaitKey) { info.GetReturnValue().Set(Nan::New(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 diff --git a/src/HighGUI.h b/src/HighGUI.h index 3994892..7b18116 100644 --- a/src/HighGUI.h +++ b/src/HighGUI.h @@ -16,6 +16,7 @@ public: JSFUNC(Show) ;JSFUNC(Destroy) ;JSFUNC(BlockingWaitKey) + ;JSFUNC(ResizeWindow) ; };