mexopencv  3.4.1
MEX interface for OpenCV library
findEssentialMat.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 
13 namespace {
16  ("Ransac", cv::RANSAC)
17  ("LMedS", cv::LMEDS);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
37  int method = cv::RANSAC;
38  double prob = 0.999;
39  double threshold = 1.0;
40  for (int i=2; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "CameraMatrix")
43  cameraMatrix = rhs[i+1].toMat(CV_64F);
44  else if (key == "Method")
45  method = (rhs[i+1].isChar()) ?
46  Method[rhs[i+1].toString()] : rhs[i+1].toInt();
47  else if (key == "Confidence")
48  prob = rhs[i+1].toDouble();
49  else if (key == "Threshold")
50  threshold = rhs[i+1].toDouble();
51  else
52  mexErrMsgIdAndTxt("mexopencv:error",
53  "Unrecognized option %s", key.c_str());
54  }
55 
56  // Process
57  Mat E, mask;
58  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
59  Mat points1(rhs[0].toMat(CV_64F)),
60  points2(rhs[1].toMat(CV_64F));
61  E = findEssentialMat(points1, points2, cameraMatrix, method,
62  prob, threshold, (nlhs>1 ? mask : noArray()));
63  }
64  else if (rhs[0].isCell() && rhs[1].isCell()) {
65  vector<Point2d> points1(rhs[0].toVector<Point2d>()),
66  points2(rhs[1].toVector<Point2d>());
67  E = findEssentialMat(points1, points2, cameraMatrix, method,
68  prob, threshold, (nlhs>1 ? mask : noArray()));
69  }
70  else
71  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
72  plhs[0] = MxArray(E);
73  if (nlhs > 1)
74  plhs[1] = MxArray(mask);
75 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
const ConstMap< string, int > Method
Estimation methods for option processing.
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)
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Mat toMat() const
Mat findEssentialMat(InputArray points1, InputArray points2, InputArray cameraMatrix, int method=RANSAC, double prob=0.999, double threshold=1.0, OutputArray mask=noArray())