mexopencv  0.1
mex interface for opencv library
findFundamentalMat.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
15  ("7Point", cv::FM_7POINT)
16  ("8Point", cv::FM_8POINT)
17  ("Ransac", cv::FM_RANSAC)
18  ("LMedS", cv::FM_LMEDS);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int method = cv::FM_RANSAC;
38  double param1 = 3.0;
39  double param2 = 0.99;
40  for (int i=2; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key=="Method")
43  method = FMMethod[rhs[i+1].toString()];
44  else if (key=="Param1")
45  param1 = rhs[i+1].toDouble();
46  else if (key=="Param2")
47  param2 = rhs[i+1].toDouble();
48  else
49  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
50  }
51 
52  // Process
53  Mat F, mask;
54  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
55  Mat points1(rhs[0].toMat(CV_32F)),
56  points2(rhs[1].toMat(CV_32F));
57  F = findFundamentalMat(points1, points2, method, param1, param2,
58  (nlhs>1 ? mask : noArray()));
59  }
60  else if (rhs[0].isCell() && rhs[1].isCell()) {
61  vector<Point2f> points1(rhs[0].toVector<Point2f>()),
62  points2(rhs[1].toVector<Point2f>());
63  F = findFundamentalMat(points1, points2, method, param1, param2,
64  (nlhs>1 ? mask : noArray()));
65  }
66  else
67  mexErrMsgIdAndTxt("mexopencv:error","Invalid argument");
68  plhs[0] = MxArray(F);
69  if (nlhs>1)
70  plhs[1] = MxArray(mask);
71 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927