1
1
#include " calib3d.h"
2
2
3
- #define FF_SET_JS_PROP (obj, prop, val ) \
4
- Nan::Set (obj, FF_V8STRING(#prop), val)
5
-
6
3
NAN_MODULE_INIT (Calib3d::Init) {
7
4
v8::Local<v8::Object> module = Nan::New<v8::Object>();
5
+
8
6
v8::Local<v8::Object> alg = Nan::New<v8::Object>();
9
7
FF_SET_JS_PROP (alg, REGULAR, Nan::New<v8::Integer>(0 ));
10
8
FF_SET_JS_PROP (alg, LMEDS, Nan::New<v8::Integer>(cv::LMEDS));
11
9
FF_SET_JS_PROP (alg, RANSAC, Nan::New<v8::Integer>(cv::RANSAC));
12
10
FF_SET_JS_PROP (alg, RHO, Nan::New<v8::Integer>(cv::RHO));
13
11
module->Set (FF_V8STRING (" robustnessAlgorithm" ), alg);
12
+
14
13
Nan::SetMethod (module, " findHomography" , FindHomography);
14
+
15
15
target->Set (Nan::New (" calib3d" ).ToLocalChecked (), module);
16
16
};
17
17
18
18
NAN_METHOD (Calib3d::FindHomography) {
19
19
if (!info[0 ]->IsObject ()) {
20
20
// TODO usage messages
21
- return Nan::ThrowError (FF_V8STRING (" findHomography - empty args object" ));
21
+ return Nan::ThrowError (FF_V8STRING (" findHomography - args object required " ));
22
22
}
23
23
v8::Local<v8::Object> args = info[0 ]->ToObject ();
24
24
25
- std::vector<cv::Point2d> srcPoints = Point::unpackJSPoint2Array (v8::Local<v8::Array>::Cast (FF::getCheckedJsProp (args, " srcPoints" )));
26
- std::vector<cv::Point2d> dstPoints = Point::unpackJSPoint2Array (v8::Local<v8::Array>::Cast (FF::getCheckedJsProp (args, " dstPoints" )));
25
+ v8::Local<v8::Object> jsSrcPoints, jsDstPoints;
26
+ std::vector<cv::Point2d> srcPoints, dstPoints;
27
+ FF_GET_JSPROP_REQUIRED (args, jsSrcPoints, srcPoints, ToObject)
28
+ FF_GET_JSPROP_REQUIRED (args, jsDstPoints, dstPoints, ToObject)
29
+ Nan::TryCatch tryCatch;
30
+ Point::unpackJSPoint2Array (srcPoints, v8::Local<v8::Array>::Cast (jsSrcPoints));
31
+ Point::unpackJSPoint2Array (dstPoints, v8::Local<v8::Array>::Cast (jsDstPoints));
32
+ if (tryCatch.HasCaught ()) {
33
+ return info.GetReturnValue ().Set (tryCatch.ReThrow ());
34
+ }
27
35
int method = 0 ;
28
36
double ransacReprojThreshold = 3 ;
29
37
cv::OutputArray mask = cv::noArray ();
@@ -35,11 +43,14 @@ NAN_METHOD(Calib3d::FindHomography) {
35
43
FF_DESTRUCTURE_TYPECHECKED_JSPROP_IFDEF (args, confidence, IsNumber, NumberValue)
36
44
37
45
if (args->HasOwnProperty (FF_V8STRING (" mask" ))) {
38
- Nan::ObjectWrap::Unwrap<Mat>(FF_GET_JSPROP (args, mask))->mat .copyTo (mask);
46
+ Nan::ObjectWrap::Unwrap<Mat>(FF_GET_JSPROP (args, mask)-> ToObject () )->mat .copyTo (mask);
39
47
}
40
48
41
49
cv::Mat homography;
42
- FF_TRY (homography = cv::findHomography (srcPoints, dstPoints, method, ransacReprojThreshold, mask, maxIters, confidence);)
50
+ FF_TRY_CATCH (homography = cv::findHomography (srcPoints, dstPoints, method, ransacReprojThreshold, mask, maxIters, confidence);)
51
+ if (tryCatch.HasCaught ()) {
52
+ return info.GetReturnValue ().Set (tryCatch.ReThrow ());
53
+ }
43
54
v8::Local<v8::Object> jsMat = Nan::NewInstance (Nan::New (Mat::constructor)->GetFunction ()).ToLocalChecked ();
44
55
Nan::ObjectWrap::Unwrap<Mat>(jsMat)->setNativeProps (homography);
45
56
info.GetReturnValue ().Set (jsMat);
0 commit comments