mexopencv  0.1
mex interface for opencv library
matchShapes.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
14 const ConstMap<string,int> ShapeMatchMethodsMap = ConstMap<string,int>
15  ("I1", CV_CONTOURS_MATCH_I1)
16  ("I2", CV_CONTOURS_MATCH_I2)
17  ("I3", CV_CONTOURS_MATCH_I3);
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<=1);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  int method = CV_CONTOURS_MATCH_I1;
37  double parameter = 0;
38  for (int i=2; i<nrhs; i+=2) {
39  string key(rhs[i].toString());
40  if (key=="Method")
41  method = ShapeMatchMethodsMap[rhs[i+1].toString()];
42  else if (key=="Parameter")
43  parameter = rhs[i+1].toDouble();
44  else
45  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
46  }
47 
48  // Process
49  double result = 0;
50  if ((rhs[0].isNumeric() || rhs[0].isLogical()) &&
51  (rhs[1].isNumeric() || rhs[1].isLogical())) {
52  Mat contour1(rhs[0].toMat()), // CV_8U, CV_16U, CV_16S, CV_32F, CV_64F
53  contour2(rhs[1].toMat());
54  result = matchShapes(contour1, contour2, method, parameter);
55  }
56  else if (rhs[0].isCell() && rhs[1].isCell()) {
57  vector<Point2f> contour1(rhs[0].toVector<Point2f>()),
58  contour2(rhs[1].toVector<Point2f>());
59  result = matchShapes(contour1, contour2, method, parameter);
60  }
61  else
62  mexErrMsgIdAndTxt("mexopencv:error","Invalid argument");
63  plhs[0] = MxArray(result);
64 }
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.
Definition: matchShapes.cpp:27
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927