mexopencv  0.1
mex interface for opencv library
computeCorrespondEpilines.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>=2 && (nrhs%2)==0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int whichImage = 1;
29  for (int i=2; i<nrhs; i+=2) {
30  string key(rhs[i].toString());
31  if (key=="WhichImage")
32  whichImage = rhs[i+1].toInt();
33  else
34  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
35  }
36  if (whichImage!=1 && whichImage!=2)
37  mexErrMsgIdAndTxt("mexopencv:error","Invalid WhichImage");
38 
39  // Process
40  Mat F(rhs[1].toMat(CV_64F));
41  if (rhs[0].isNumeric()) {
42  Mat points(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)), lines;
43  bool cn1 = (points.channels() == 1 && (points.cols == 2 || points.cols == 3));
44  if (cn1) points = points.reshape(points.cols, 0); // Nxd => Nx1xd
45  computeCorrespondEpilines(points, whichImage, F, lines);
46  if (cn1) lines = lines.reshape(1,0); // Nx1x3 => Nx3
47  plhs[0] = MxArray(lines);
48  }
49  else if (rhs[0].isCell()) {
50  vector<Point2d> points(rhs[0].toVector<Point2d>());
51  vector<Point3d> lines;
52  computeCorrespondEpilines(points, whichImage, F, lines);
53  plhs[0] = MxArray(lines); // {[a,b,c], ...}
54  }
55  else
56  mexErrMsgIdAndTxt("mexopencv:error","Invalid input");
57 }
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.