mexopencv  0.1
mex interface for opencv library
correctMatches.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 && nlhs<=2);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Process
28  Mat F(rhs[0].toMat(CV_64F));
29  if (rhs[1].isNumeric() && rhs[2].isNumeric()) {
30  Mat points1(rhs[1].toMat(CV_64F)),
31  points2(rhs[2].toMat(CV_64F)),
32  newPoints1, newPoints2;
33  correctMatches(F, points1.reshape(2,1), points2.reshape(2,1),
34  newPoints1, newPoints2); // function requires 1xNx2 input points
35  if (points1.channels() == 1) // 1xNx2 -> Nx2 (to match input)
36  newPoints1 = newPoints1.reshape(1, newPoints1.cols);
37  if (points2.channels() == 1)
38  newPoints2 = newPoints2.reshape(1, newPoints2.cols);
39  plhs[0] = MxArray(newPoints1);
40  if (nlhs > 1)
41  plhs[1] = MxArray(newPoints2);
42  }
43  else if (rhs[1].isCell() && rhs[2].isCell()) {
44  vector<Point2d> points1(rhs[1].toVector<Point2d>()),
45  points2(rhs[2].toVector<Point2d>()),
46  newPoints1, newPoints2;
47  correctMatches(F, points1, points2, newPoints1, newPoints2);
48  plhs[0] = MxArray(newPoints1);
49  if (nlhs > 1)
50  plhs[1] = MxArray(newPoints2);
51  }
52  else
53  mexErrMsgIdAndTxt("mexopencv:error", "Invalid input");
54 }
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.