Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 4b948f2

Browse files
Merge pull request justadudewhohacks#62 from codyseibert/task/adding_affine_perspective_transform
Adding getAffineTransform and getPerspectiveTransform
2 parents 90ba4f1 + e126d41 commit 4b948f2

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

cc/modules/imgproc/imgproc.cc

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ NAN_MODULE_INIT(Imgproc::Init) {
2929
Nan::SetMethod(target, "calcHist", CalcHist);
3030
Nan::SetMethod(target, "plot1DHist", Plot1DHist);
3131
Nan::SetMethod(target, "fitLine", FitLine);
32+
Nan::SetMethod(target, "getAffineTransform", GetAffineTransform);
33+
Nan::SetMethod(target, "getPerspectiveTransform", GetPerspectiveTransform);
3234
#if CV_VERSION_MINOR > 1
3335
Nan::SetMethod(target, "canny", Canny);
3436
#endif
@@ -61,6 +63,45 @@ NAN_METHOD(Imgproc::GetRotationMatrix2D) {
6163
FF_RETURN(jsRotationMat);
6264
}
6365

66+
NAN_METHOD(Imgproc::GetAffineTransform) {
67+
FF_METHOD_CONTEXT("GetAffineTransform");
68+
69+
FF_ARG_ARRAY(0, FF_ARR jsSrcPoints);
70+
FF_ARG_ARRAY(1, FF_ARR jsDstPoints);
71+
72+
// TODO FF_ARG_UNPACK_ARRAY_INSTANCE
73+
Nan::TryCatch tryCatch;
74+
std::vector<cv::Point2f> srcPoints, dstPoints;
75+
Point::unpackJSPoint2Array<float>(srcPoints, jsSrcPoints);
76+
Point::unpackJSPoint2Array<float>(dstPoints, jsDstPoints);
77+
if (tryCatch.HasCaught()) {
78+
return info.GetReturnValue().Set(tryCatch.ReThrow());
79+
}
80+
81+
FF_OBJ jsMat = FF_NEW_INSTANCE(Mat::constructor);
82+
FF_UNWRAP_MAT_AND_GET(jsMat) = cv::getAffineTransform(srcPoints, dstPoints);
83+
FF_RETURN(jsMat);
84+
}
85+
86+
NAN_METHOD(Imgproc::GetPerspectiveTransform) {
87+
FF_METHOD_CONTEXT("GetPerspectiveTransform");
88+
89+
FF_ARG_ARRAY(0, FF_ARR jsSrcPoints);
90+
FF_ARG_ARRAY(1, FF_ARR jsDstPoints);
91+
92+
// TODO FF_ARG_UNPACK_ARRAY_INSTANCE
93+
Nan::TryCatch tryCatch;
94+
std::vector<cv::Point2f> srcPoints, dstPoints;
95+
Point::unpackJSPoint2Array<float>(srcPoints, jsSrcPoints);
96+
Point::unpackJSPoint2Array<float>(dstPoints, jsDstPoints);
97+
if (tryCatch.HasCaught()) {
98+
return info.GetReturnValue().Set(tryCatch.ReThrow());
99+
}
100+
101+
FF_OBJ jsMat = FF_NEW_INSTANCE(Mat::constructor);
102+
FF_UNWRAP_MAT_AND_GET(jsMat) = cv::getPerspectiveTransform(srcPoints, dstPoints);
103+
FF_RETURN(jsMat);
104+
}
64105

65106
NAN_METHOD(Imgproc::CalcHist) {
66107
FF_METHOD_CONTEXT("CalcHist");
@@ -230,4 +271,4 @@ NAN_METHOD(Imgproc::Canny) {
230271

231272
FF_RETURN(jsMat);
232273
}
233-
#endif
274+
#endif

cc/modules/imgproc/imgproc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ class Imgproc {
1414
static NAN_METHOD(CalcHist);
1515
static NAN_METHOD(Plot1DHist);
1616
static NAN_METHOD(FitLine);
17+
static NAN_METHOD(GetAffineTransform);
18+
static NAN_METHOD(GetPerspectiveTransform);
1719
#if CV_VERSION_MINOR > 1
1820
static NAN_METHOD(Canny);
1921
#endif
2022
};
2123

22-
#endif
24+
#endif

0 commit comments

Comments
 (0)