mexopencv  3.4.1
MEX interface for OpenCV library
estimateAffinePartial2D.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 
13 namespace {
16  ("Ransac", cv::RANSAC)
17  ("LMedS", cv::LMEDS);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  int method = cv::RANSAC;
37  double ransacReprojThreshold = 3.0;
38  size_t maxIters = 2000;
39  double confidence = 0.99;
40  size_t refineIters = 10;
41  for (int i=2; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key == "Method")
44  method = MethodsMap[rhs[i+1].toString()];
45  else if (key == "RansacThreshold")
46  ransacReprojThreshold = rhs[i+1].toDouble();
47  else if (key == "MaxIters")
48  maxIters = rhs[i+1].toInt();
49  else if (key == "Confidence")
50  confidence = rhs[i+1].toDouble();
51  else if (key == "RefineIters")
52  refineIters = rhs[i+1].toInt();
53  else
54  mexErrMsgIdAndTxt("mexopencv:error",
55  "Unrecognized option %s", key.c_str());
56  }
57 
58  // Process
59  Mat out, inliers;
60  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
61  Mat from(rhs[0].toMat(CV_32F).reshape(2,0)), // CV_32FC2
62  to(rhs[1].toMat(CV_32F).reshape(2,0));
63  out = estimateAffinePartial2D(from, to, (nlhs>1 ? inliers : noArray()),
64  method, ransacReprojThreshold, maxIters, confidence, refineIters);
65  }
66  else if (rhs[0].isCell() && rhs[1].isCell()) {
67  vector<Point2f> from(rhs[0].toVector<Point2f>()),
68  to(rhs[1].toVector<Point2f>());
69  out = estimateAffinePartial2D(from, to, (nlhs>1 ? inliers : noArray()),
70  method, ransacReprojThreshold, maxIters, confidence, refineIters);
71  }
72  else
73  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
74  plhs[0] = MxArray(out);
75  if (nlhs>1)
76  plhs[1] = MxArray(inliers);
77 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers=noArray(), int method=RANSAC, double ransacReprojThreshold=3, size_t maxIters=2000, double confidence=0.99, size_t refineIters=10)
#define CV_32F
InputOutputArray noArray()
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...
const ConstMap< string, int > MethodsMap
Estimation methods for option processing.
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.
T c_str(T... args)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const