mexopencv  3.4.1
MEX interface for OpenCV library
recoverPose.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/calib3d.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=5);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
30  double distanceThresh = 50.0;
31  Mat mask;
32  for (int i=3; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "CameraMatrix")
35  cameraMatrix = rhs[i+1].toMat(CV_64F);
36  else if (key == "DistanceThreshold")
37  distanceThresh = rhs[i+1].toDouble();
38  else if (key == "Mask")
39  mask = rhs[i+1].toMat(CV_8U);
40  else
41  mexErrMsgIdAndTxt("mexopencv:error",
42  "Unrecognized option %s", key.c_str());
43  }
44 
45  // Process
46  Mat E(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)),
47  R, t, triangulatedPoints;
48  int good = 0;
49  if (rhs[1].isNumeric() && rhs[2].isNumeric()) {
50  Mat points1(rhs[1].toMat(CV_64F)),
51  points2(rhs[2].toMat(CV_64F));
52  good = recoverPose(E, points1, points2, cameraMatrix, R, t,
53  distanceThresh, (nlhs>3 ? mask : noArray()),
54  (nlhs>4 ? triangulatedPoints : noArray()));
55  }
56  else if (rhs[1].isCell() && rhs[2].isCell()) {
57  vector<Point2d> points1(rhs[1].toVector<Point2d>()),
58  points2(rhs[2].toVector<Point2d>());
59  good = recoverPose(E, points1, points2, cameraMatrix, R, t,
60  distanceThresh, (nlhs>3 ? mask : noArray()),
61  (nlhs>4 ? triangulatedPoints : noArray()));
62  }
63  else
64  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
65  plhs[0] = MxArray(R);
66  if (nlhs > 1)
67  plhs[1] = MxArray(t);
68  if (nlhs > 2)
69  plhs[2] = MxArray(good);
70  if (nlhs > 3)
71  plhs[3] = MxArray(mask);
72  if (nlhs > 4)
73  plhs[4] = MxArray(triangulatedPoints);
74 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_32F
InputOutputArray noArray()
#define CV_64F
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
Global constant definitions.
T c_str(T... args)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: recoverPose.cpp:20
int recoverPose(InputArray E, InputArray points1, InputArray points2, InputArray cameraMatrix, OutputArray R, OutputArray t, InputOutputArray mask=noArray())
cv::Mat toMat() const