mexopencv  0.1
mex interface for opencv library
recoverPose.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=4);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
29  Mat mask;
30  for (int i=3; i<nrhs; i+=2) {
31  string key(rhs[i].toString());
32  if (key == "CameraMatrix")
33  cameraMatrix = rhs[i+1].toMat(CV_64F);
34  else if (key == "Mask")
35  mask = rhs[i+1].toMat(CV_8U);
36  else
37  mexErrMsgIdAndTxt("mexopencv:error",
38  "Unrecognized option %s",key.c_str());
39  }
40 
41  // Process
42  Mat E(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)),
43  R, t;
44  int good = 0;
45  if (rhs[1].isNumeric() && rhs[2].isNumeric()) {
46  Mat points1(rhs[1].toMat(CV_64F)),
47  points2(rhs[2].toMat(CV_64F));
48  good = recoverPose(E, points1, points2, cameraMatrix, R, t,
49  (nlhs>3 ? mask : noArray()));
50  }
51  else if (rhs[1].isCell() && rhs[2].isCell()) {
52  vector<Point2d> points1(rhs[1].toVector<Point2d>()),
53  points2(rhs[2].toVector<Point2d>());
54  good = recoverPose(E, points1, points2, cameraMatrix, R, t,
55  (nlhs>3 ? mask : noArray()));
56  }
57  else
58  mexErrMsgIdAndTxt("mexopencv:error", "Invalid input");
59  plhs[0] = MxArray(R);
60  if (nlhs > 1)
61  plhs[1] = MxArray(t);
62  if (nlhs > 2)
63  plhs[2] = MxArray(good);
64  if (nlhs > 3)
65  plhs[3] = MxArray(mask);
66 }
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: recoverPose.cpp:19