From 51631b307ea0ce997909853f0c98abb630a991b1 Mon Sep 17 00:00:00 2001 From: Max Ehrlich Date: Thu, 5 Feb 2015 14:31:37 -0500 Subject: [PATCH] Added computeCorrespondEpilines --- src/Calib3D.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- src/Calib3D.h | 2 ++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Calib3D.cc b/src/Calib3D.cc index 67d9927..8d6a43f 100644 --- a/src/Calib3D.cc +++ b/src/Calib3D.cc @@ -131,6 +131,7 @@ void Calib3D::Init(Handle target) NODE_SET_METHOD(obj, "getOptimalNewCameraMatrix", GetOptimalNewCameraMatrix); NODE_SET_METHOD(obj, "stereoCalibrate", StereoCalibrate); NODE_SET_METHOD(obj, "stereoRectify", StereoRectify); + NODE_SET_METHOD(obj, "computeCorrespondEpilines", ComputeCorrespondEpilines); target->Set(NanNew("calib3d"), obj); } @@ -448,7 +449,7 @@ NAN_METHOD(Calib3D::StereoCalibrate) } } -// cv::stereoCalibrate +// cv::stereoRectify NAN_METHOD(Calib3D::StereoRectify) { NanEscapableScope(); @@ -500,7 +501,50 @@ NAN_METHOD(Calib3D::StereoRectify) // Return the recification parameters NanReturnValue(ret); - + + } catch (cv::Exception &e) { + const char *err_msg = e.what(); + NanThrowError(err_msg); + NanReturnUndefined(); + } +} + +// cv::stereoRectify +NAN_METHOD(Calib3D::StereoRectify) +{ + NanEscapableScope(); + + try { + // Get the arguments + + // Arg0, the image points + std::vector points = points2fFromArray(args[0]); + + // Arg1, the image index (1 or 2) + int whichImage = int(args[1]->ToNumber()->Value()); + + // Arg2, the fundamental matrix + cv::Mat F = matFromMatrix(args[2]); + + // compute the lines + std::vector lines; + cv::computeCorrespondEpilines(points, whichImage, F, lines); + + // Convert the lines to an array of objects (ax + by + c = 0) + Local linesArray = NanNew(lines.size()); + for(unsigned int i = 0; i < lines.size(); i++) + { + Local line_data = NanNew(); + line_data->Set(NanNew("a"), NanNew(corners[i][0])); + line_data->Set(NanNew("b"), NanNew(corners[i][1])); + line_data->Set(NanNew("c"), NanNew(corners[i][2])); + + linesArray->Set(NanNew(i), line_data); + } + + // Return the lines + NanReturnValue(linesArray); + } catch (cv::Exception &e) { const char *err_msg = e.what(); NanThrowError(err_msg); diff --git a/src/Calib3D.h b/src/Calib3D.h index cf1d190..9d5afbd 100644 --- a/src/Calib3D.h +++ b/src/Calib3D.h @@ -22,6 +22,8 @@ public: static NAN_METHOD(StereoCalibrate); static NAN_METHOD(StereoRectify); + + static NAN_METHOD(ComputeCorrespondEpilines); }; #endif