@@ -4,31 +4,43 @@ Nan::Persistent<v8::FunctionTemplate> BFMatcher::constructor;
4
4
5
5
NAN_MODULE_INIT (BFMatcher::Init) {
6
6
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(BFMatcher::New);
7
+ v8::Local<v8::ObjectTemplate> instanceTemplate = ctor->InstanceTemplate ();
8
+
9
+ BFMatcher::Init (ctor);
7
10
constructor.Reset (ctor);
8
- ctor->InstanceTemplate ()->SetInternalFieldCount (1 );
9
- ctor->SetClassName (Nan::New (" BFMatcher" ).ToLocalChecked ());
11
+ instanceTemplate->SetInternalFieldCount (1 );
12
+
13
+ // ctor->SetClassName(Nan::New("BFMatcher").ToLocalChecked());
14
+ ctor->SetClassName (FF_NEW_STRING (" BFMatcher" ));
10
15
11
- Nan::SetAccessor (ctor->InstanceTemplate (), Nan::New (" normType" ).ToLocalChecked (), GetNormType);
12
- Nan::SetAccessor (ctor->InstanceTemplate (), Nan::New (" crossCheck" ).ToLocalChecked (), GetCrossCheck);
13
16
14
- target->Set (Nan::New (" BFMatcher" ).ToLocalChecked (), ctor->GetFunction ());
17
+ Nan::SetAccessor (instanceTemplate, Nan::New (" normType" ).ToLocalChecked (), BFMatcher::GetNormType);
18
+ Nan::SetAccessor (instanceTemplate, Nan::New (" crossCheck" ).ToLocalChecked (), BFMatcher::GetCrossCheck);
19
+
20
+ // target->Set(Nan::New("BFMatcher").ToLocalChecked(), ctor->GetFunction());
21
+ target->Set (FF_NEW_STRING (" CascadeClassifier" ), ctor->GetFunction ());
15
22
};
16
23
17
24
NAN_METHOD (BFMatcher::New) {
18
25
FF_METHOD_CONTEXT (" BFMatcher::New" );
19
26
BFMatcher* self = new BFMatcher ();
20
- if (info.Length () > 0 ) {
21
- FF_ARG_INT (0 , int normType);
22
- FF_ARG_INT (1 , bool crossCheck);
23
27
24
- self->bfmatcher = cv::BFMatcher (normType, crossCheck);
25
- }
26
- self->Wrap (info.Holder ());
27
- info.GetReturnValue ().Set (info.Holder ());
28
- }
28
+ // optional args
29
+ bool hasOptArgsObj = FF_HAS_ARG (0 ) && info[0 ]->IsObject ();
30
+ FF_OBJ optArgs = hasOptArgsObj ? info[0 ]->ToObject () : FF_NEW_OBJ ();
31
+
32
+ FF_GET_NUMBER_IFDEF (optArgs, double normType, " normType" , cv::NORM_L2);
33
+ FF_GET_BOOL_IFDEF (optArgs, bool crossCheck, " crossCheck" , false );
29
34
30
- NAN_METHOD (BFMatcher::Clone) {
31
- GaussianBlurWorker worker (Mat::Converter::unwrap (info.This ()));
32
- FF_WORKER_SYNC (" Mat::GaussianBlur" , worker);
33
- info.GetReturnValue ().Set (worker.getReturnValue ());
35
+ if (!hasOptArgsObj) {
36
+ FF_ARG_NUMBER_IFDEF (0 , normType, normType);
37
+ FF_ARG_INT_IFDEF (1 , crossCheck, crossCheck);
38
+ }
39
+
40
+ self->Wrap (info.Holder ());
41
+ self->bfmatcher = cv::BFMatcher::create (
42
+ normType,
43
+ crossCheck
44
+ );
45
+ FF_RETURN (info.Holder ());
34
46
}
0 commit comments