Skip to content

Commit

Permalink
undistortPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed May 6, 2019
1 parent e2f4438 commit 45528fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cc/modules/imgproc/imgproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ NAN_MODULE_INIT(Imgproc::Init) {
Nan::SetMethod(target, "fitLine", FitLine);
Nan::SetMethod(target, "getAffineTransform", GetAffineTransform);
Nan::SetMethod(target, "getPerspectiveTransform", GetPerspectiveTransform);
Nan::SetMethod(target, "undistortPoints", UndistortPoints);
Nan::SetMethod(target, "getTextSize", GetTextSize);
Nan::SetMethod(target, "getTextSizeAsync", GetTextSizeAsync);
Nan::SetMethod(target, "applyColorMap", ApplyColorMap);
Expand Down Expand Up @@ -102,7 +103,25 @@ NAN_METHOD(Imgproc::GetPerspectiveTransform) {
FF_UNWRAP_MAT_AND_GET(jsMat) = cv::getPerspectiveTransform(srcPoints, dstPoints);
FF_RETURN(jsMat);
}
NAN_METHOD(Imgproc::UndistortPoints) {
FF_METHOD_CONTEXT("UndistortPoints");

FF_ARG_ARRAY(0, FF_ARR jsSrcPoints);
FF_ARG_INSTANCE(1, cv::Mat cameraMatrix, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
FF_ARG_INSTANCE(2, cv::Mat distCoeffs, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
FF_ARG_INSTANCE_IFDEF(3, cv::Mat newCameraMatrix, Mat::constructor, FF_UNWRAP_MAT_AND_GET, cameraMatrix);

Nan::TryCatch tryCatch;
std::vector<cv::Point2f> srcPoints;
Point::unpackJSPoint2Array<float>(srcPoints, jsSrcPoints);
if (tryCatch.HasCaught()) {
return info.GetReturnValue().Set(tryCatch.ReThrow());
}

std::vector<cv::Point2f> destPoints;
cv::undistortPoints(srcPoints, destPoints, cameraMatrix, distCoeffs, newCameraMatrix);
FF_RETURN(Point::packJSPoint2Array<float>(destPoints));
}
NAN_METHOD(Imgproc::CalcHist) {
FF_METHOD_CONTEXT("CalcHist");

Expand Down
1 change: 1 addition & 0 deletions cc/modules/imgproc/imgproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Imgproc {
static NAN_METHOD(GetRotationMatrix2D);
static NAN_METHOD(GetAffineTransform);
static NAN_METHOD(GetPerspectiveTransform);
static NAN_METHOD(UndistortPoints);
static NAN_METHOD(CalcHist);
static NAN_METHOD(Plot1DHist);
static NAN_METHOD(FitLine);
Expand Down

0 comments on commit 45528fc

Please sign in to comment.