mexopencv  3.4.1
MEX interface for OpenCV library
findFundamentalMat.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  ("7Point", cv::FM_7POINT)
17  ("8Point", cv::FM_8POINT)
18  ("Ransac", cv::FM_RANSAC)
19  ("LMedS", cv::FM_LMEDS);
20 }
21 
29 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
30 {
31  // Check the number of arguments
32  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
33 
34  // Argument vector
35  vector<MxArray> rhs(prhs, prhs+nrhs);
36 
37  // Option processing
38  int method = cv::FM_RANSAC;
39  double ransacReprojThreshold = 3.0;
40  double confidence = 0.99;
41  for (int i=2; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key == "Method")
44  method = FMMethod[rhs[i+1].toString()];
45  else if (key == "RansacReprojThreshold")
46  ransacReprojThreshold = rhs[i+1].toDouble();
47  else if (key == "Confidence")
48  confidence = rhs[i+1].toDouble();
49  else
50  mexErrMsgIdAndTxt("mexopencv:error",
51  "Unrecognized option %s", key.c_str());
52  }
53 
54  // Process
55  Mat F, mask;
56  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
57  Mat points1(rhs[0].toMat(CV_32F)),
58  points2(rhs[1].toMat(CV_32F));
59  F = findFundamentalMat(points1, points2, method,
60  ransacReprojThreshold, confidence,
61  (nlhs>1 ? mask : noArray()));
62  }
63  else if (rhs[0].isCell() && rhs[1].isCell()) {
64  vector<Point2f> points1(rhs[0].toVector<Point2f>()),
65  points2(rhs[1].toVector<Point2f>());
66  F = findFundamentalMat(points1, points2, method,
67  ransacReprojThreshold, confidence,
68  (nlhs>1 ? mask : noArray()));
69  }
70  else
71  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
72  plhs[0] = MxArray(F);
73  if (nlhs>1)
74  plhs[1] = MxArray(mask); // MxArray(mask,mxLOGICAL_CLASS)
75 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
FM_RANSAC
STL namespace.
FM_8POINT
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
Mat findFundamentalMat(InputArray points1, InputArray points2, int method=FM_RANSAC, double ransacReprojThreshold=3., double confidence=0.99, OutputArray mask=noArray())
#define CV_32F
InputOutputArray noArray()
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.
FM_LMEDS
Global constant definitions.
T c_str(T... args)
FM_7POINT
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
const ConstMap< string, int > FMMethod
Method for option processing.
cv::Mat toMat() const