mexopencv  0.1
mex interface for opencv library
cornerSubPix.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<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Size winSize(3,3);
29  Size zeroZone(-1,-1);
30  TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001);
31  for (int i=2; i<nrhs; i+=2) {
32  string key(rhs[i].toString());
33  if (key=="WinSize")
34  winSize = rhs[i+1].toSize();
35  else if (key=="ZeroZone")
36  zeroZone = rhs[i+1].toSize();
37  else if (key=="Criteria")
38  criteria = rhs[i+1].toTermCriteria();
39  else
40  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
41  }
42 
43  // Process
44  Mat image(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F));
45  if (rhs[1].isNumeric()) {
46  Mat corners(rhs[1].toMat(CV_32F));
47  cornerSubPix(image, corners, winSize, zeroZone, criteria);
48  plhs[0] = MxArray(corners);
49  }
50  else if (rhs[1].isCell()) {
51  vector<Point2f> corners(rhs[1].toVector<Point2f>());
52  cornerSubPix(image, corners, winSize, zeroZone, criteria);
53  plhs[0] = MxArray(corners);
54  }
55  else
56  mexErrMsgIdAndTxt("mexopencv:error", "Invalid input");
57 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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.