mexopencv  3.4.1
MEX interface for OpenCV library
correctMatches.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/calib3d.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs==3 && nlhs<=2);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Process
29  Mat F(rhs[0].toMat(CV_64F));
30  if (rhs[1].isNumeric() && rhs[2].isNumeric()) {
31  Mat points1(rhs[1].toMat(CV_64F)),
32  points2(rhs[2].toMat(CV_64F)),
33  newPoints1, newPoints2;
34  correctMatches(F, points1.reshape(2,1), points2.reshape(2,1),
35  newPoints1, newPoints2); // function requires 1xNx2 input points
36  if (points1.channels() == 1) // 1xNx2 -> Nx2 (to match input)
37  newPoints1 = newPoints1.reshape(1, newPoints1.cols);
38  if (points2.channels() == 1)
39  newPoints2 = newPoints2.reshape(1, newPoints2.cols);
40  plhs[0] = MxArray(newPoints1);
41  if (nlhs > 1)
42  plhs[1] = MxArray(newPoints2);
43  }
44  else if (rhs[1].isCell() && rhs[2].isCell()) {
45  vector<Point2d> points1(rhs[1].toVector<Point2d>()),
46  points2(rhs[2].toVector<Point2d>()),
47  newPoints1, newPoints2;
48  correctMatches(F, points1, points2, newPoints1, newPoints2);
49  plhs[0] = MxArray(newPoints1);
50  if (nlhs > 1)
51  plhs[1] = MxArray(newPoints2);
52  }
53  else
54  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
55 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
Mat reshape(int cn, int rows=0) const
#define CV_64F
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
void correctMatches(InputArray F, InputArray points1, InputArray points2, OutputArray newPoints1, OutputArray newPoints2)
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Mat toMat() const