mexopencv  3.4.1
MEX interface for OpenCV library
estimateAffine3D.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>=2 && (nrhs%2)==0 && nlhs<=3);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  double ransacThreshold = 3.0;
30  double confidence = 0.99;
31  for (int i=2; i<nrhs; i+=2) {
32  string key(rhs[i].toString());
33  if (key == "RansacThreshold")
34  ransacThreshold = rhs[i+1].toDouble();
35  else if (key == "Confidence")
36  confidence = rhs[i+1].toDouble();
37  else
38  mexErrMsgIdAndTxt("mexopencv:error",
39  "Unrecognized option %s", key.c_str());
40  }
41 
42  // Process
43  Mat out, inliers;
44  int result = 0;
45  if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
46  Mat src(rhs[0].toMat(CV_32F)),
47  dst(rhs[1].toMat(CV_32F));
48  result = estimateAffine3D(src, dst, out,
49  (nlhs>1 ? inliers : noArray()), ransacThreshold, confidence);
50  }
51  else if (rhs[0].isCell() && rhs[1].isCell()) {
52  vector<Point3f> src(rhs[0].toVector<Point3f>()),
53  dst(rhs[1].toVector<Point3f>());
54  result = estimateAffine3D(src, dst, out,
55  (nlhs>1 ? inliers : noArray()), ransacThreshold, confidence);
56  }
57  else
58  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
59  plhs[0] = MxArray(out);
60  if (nlhs>1)
61  plhs[1] = MxArray(inliers);
62  if (nlhs>2)
63  plhs[2] = MxArray(result);
64 }
int estimateAffine3D(InputArray src, InputArray dst, OutputArray out, OutputArray inliers, double ransacThreshold=3, double confidence=0.99)
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#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...
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.
cv::Mat toMat() const