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