55
66#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
77
8- Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;
8+ Nan:: Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;
99
1010void BackgroundSubtractorWrap::Init (Handle<Object> target) {
11- NanScope () ;
11+ Nan::HandleScope scope ;
1212
1313 // Constructor
14- Local<FunctionTemplate> ctor = NanNew <FunctionTemplate>(BackgroundSubtractorWrap::New);
15- NanAssignPersistent ( constructor, ctor);
14+ Local<FunctionTemplate> ctor = Nan::New <FunctionTemplate>(BackgroundSubtractorWrap::New);
15+ constructor. Reset ( ctor);
1616 ctor->InstanceTemplate ()->SetInternalFieldCount (1 );
17- ctor->SetClassName (NanNew (" BackgroundSubtractor" ));
17+ ctor->SetClassName (Nan::New (" BackgroundSubtractor" ). ToLocalChecked ( ));
1818
19- NODE_SET_METHOD (ctor, " createMOG" , CreateMOG);
20- NODE_SET_PROTOTYPE_METHOD (ctor, " applyMOG" , ApplyMOG);
19+ Nan::SetMethod (ctor, " createMOG" , CreateMOG);
20+ Nan::SetPrototypeMethod (ctor, " applyMOG" , ApplyMOG);
2121
22- target->Set (NanNew (" BackgroundSubtractor" ), ctor->GetFunction ());
22+ target->Set (Nan::New (" BackgroundSubtractor" ). ToLocalChecked ( ), ctor->GetFunction ());
2323}
2424
2525NAN_METHOD (BackgroundSubtractorWrap::New) {
26- NanScope () ;
26+ Nan::HandleScope scope ;
2727
28- if (args .This ()->InternalFieldCount () == 0 ) {
28+ if (info .This ()->InternalFieldCount () == 0 ) {
2929 JSTHROW_TYPE (" Cannot Instantiate without new" )
3030 }
3131
3232 // Create MOG by default
3333 cv::Ptr<cv::BackgroundSubtractor> bg;
3434 BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap (bg);
35- pt->Wrap (args .This ());
35+ pt->Wrap (info .This ());
3636
37- NanReturnValue (args .This ());
37+ info. GetReturnValue (). Set (info .This ());
3838}
3939
4040NAN_METHOD (BackgroundSubtractorWrap::CreateMOG) {
41- NanScope () ;
41+ Nan::HandleScope scope ;
4242
4343 // int history = 200;
4444 // int nmixtures = 5;
4545 // double backgroundRatio = 0.7;
4646 // double noiseSigma = 0;
4747 //
48- // if(args .Length() > 1){
48+ // if(info .Length() > 1){
4949 // INT_FROM_ARGS(history, 0)
5050 // INT_FROM_ARGS(nmixtures, 1)
5151 // DOUBLE_FROM_ARGS(backgroundRatio, 2)
5252 // DOUBLE_FROM_ARGS(noiseSigma, 3)
5353 // }
5454
55- Local<Object> n = NanNew (BackgroundSubtractorWrap::constructor)->GetFunction ()->NewInstance ();
55+ Local<Object> n = Nan::New (BackgroundSubtractorWrap::constructor)->GetFunction ()->NewInstance ();
5656
5757 cv::Ptr<cv::BackgroundSubtractor> bg;
5858 BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap (bg);
5959
6060 pt->Wrap (n);
61- NanReturnValue ( n );
61+ info. GetReturnValue (). Set ( n );
6262}
6363
6464// Fetch foreground mask
@@ -67,32 +67,32 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
6767 REQ_FUN_ARG (1 , cb);
6868
6969 Local<Value> argv[2 ];
70- if (args .Length () == 0 ) {
71- argv[0 ] = NanNew (" Input image missing" );
72- argv[1 ] = NanNull ();
73- cb->Call (NanGetCurrentContext ()->Global (), 2 , argv);
74- NanReturnUndefined () ;
70+ if (info .Length () == 0 ) {
71+ argv[0 ] = Nan::New (" Input image missing" ). ToLocalChecked ( );
72+ argv[1 ] = Nan::Null ();
73+ cb->Call (Nan::GetCurrentContext ()->Global (), 2 , argv);
74+ return ;
7575 }
7676
7777 try {
7878 Local<Object> fgMask =
79- NanNew (Matrix::constructor)->GetFunction ()->NewInstance ();
80- Matrix *img = ObjectWrap::Unwrap<Matrix>(fgMask);
79+ Nan::New (Matrix::constructor)->GetFunction ()->NewInstance ();
80+ Matrix *img = Nan:: ObjectWrap::Unwrap<Matrix>(fgMask);
8181
8282 cv::Mat mat;
83- if (Buffer::HasInstance (args [0 ])) {
84- uint8_t *buf = (uint8_t *) Buffer::Data (args [0 ]->ToObject ());
85- unsigned len = Buffer::Length (args [0 ]->ToObject ());
83+ if (Buffer::HasInstance (info [0 ])) {
84+ uint8_t *buf = (uint8_t *) Buffer::Data (info [0 ]->ToObject ());
85+ unsigned len = Buffer::Length (info [0 ]->ToObject ());
8686 cv::Mat *mbuf = new cv::Mat (len, 1 , CV_64FC1, buf);
8787 mat = cv::imdecode (*mbuf, -1 );
8888 // mbuf->release();
8989 } else {
90- Matrix *_img = ObjectWrap::Unwrap<Matrix>(args [0 ]->ToObject ());
90+ Matrix *_img = Nan:: ObjectWrap::Unwrap<Matrix>(info [0 ]->ToObject ());
9191 mat = (_img->mat ).clone ();
9292 }
9393
9494 if (mat.empty ()) {
95- return NanThrowTypeError (" Error loading file" );
95+ return Nan::ThrowTypeError (" Error loading file" );
9696 }
9797
9898 cv::Mat _fgMask;
@@ -101,20 +101,20 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
101101 img->mat = _fgMask;
102102 mat.release ();
103103
104- argv[0 ] = NanNull ();
104+ argv[0 ] = Nan::Null ();
105105 argv[1 ] = fgMask;
106106
107107 TryCatch try_catch;
108- cb->Call (NanGetCurrentContext ()->Global (), 2 , argv);
108+ cb->Call (Nan::GetCurrentContext ()->Global (), 2 , argv);
109109
110110 if (try_catch.HasCaught ()) {
111111 FatalException (try_catch);
112112 }
113- NanReturnUndefined () ;
113+ return ;
114114 } catch (cv::Exception& e) {
115115 const char * err_msg = e.what ();
116- NanThrowError (err_msg);
117- NanReturnUndefined () ;
116+ Nan::ThrowError (err_msg);
117+ return ;
118118 }
119119}
120120
0 commit comments