mexopencv  0.1
mex interface for opencv library
findEssentialMat.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  ("Ransac", cv::RANSAC)
16  ("LMedS", cv::LMEDS);
17 }
18 
26 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
27 {
28  // Check the number of arguments
29  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
30 
31  // Argument vector
32  vector<MxArray> rhs(prhs, prhs+nrhs);
33 
34  // Option processing
35  Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
36  int method = cv::RANSAC;
37  double prob = 0.999;
38  double threshold = 1.0;
39  for (int i=2; i<nrhs; i+=2) {
40  string key(rhs[i].toString());
41  if (key == "CameraMatrix")
42  cameraMatrix = rhs[i+1].toMat(CV_64F);
43  else if (key == "Method")
44  method = (rhs[i+1].isChar()) ?
45  Method[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else if (key == "Confidence")
47  prob = rhs[i+1].toDouble();
48  else if (key == "Threshold")
49  threshold = rhs[i+1].toDouble();
50  else
51  mexErrMsgIdAndTxt("mexopencv:error",
52  "Unrecognized option %s",key.c_str());
53  }
54 
55  // Process
56  Mat E, mask;
57  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
58  Mat points1(rhs[0].toMat(CV_64F)),
59  points2(rhs[1].toMat(CV_64F));
60  E = findEssentialMat(points1, points2, cameraMatrix, method,
61  prob, threshold, (nlhs>1 ? mask : noArray()));
62  }
63  else if (rhs[0].isCell() && rhs[1].isCell()) {
64  vector<Point2d> points1(rhs[0].toVector<Point2d>()),
65  points2(rhs[1].toVector<Point2d>());
66  E = findEssentialMat(points1, points2, cameraMatrix, method,
67  prob, threshold, (nlhs>1 ? mask : noArray()));
68  }
69  else
70  mexErrMsgIdAndTxt("mexopencv:error", "Invalid input");
71  plhs[0] = MxArray(E);
72  if (nlhs > 1)
73  plhs[1] = MxArray(mask);
74 }
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.