mexopencv  3.4.1
MEX interface for OpenCV library
cornerSubPix.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/imgproc.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<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  Size winSize(3,3);
30  Size zeroZone(-1,-1);
31  TermCriteria criteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001);
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "WinSize")
35  winSize = rhs[i+1].toSize();
36  else if (key == "ZeroZone")
37  zeroZone = rhs[i+1].toSize();
38  else if (key == "Criteria")
39  criteria = rhs[i+1].toTermCriteria();
40  else
41  mexErrMsgIdAndTxt("mexopencv:error",
42  "Unrecognized option %s", key.c_str());
43  }
44 
45  // Process
46  Mat image(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F));
47  if (rhs[1].isNumeric()) {
48  Mat corners(rhs[1].toMat(CV_32F));
49  cornerSubPix(image, corners, winSize, zeroZone, criteria);
50  plhs[0] = MxArray(corners);
51  }
52  else if (rhs[1].isCell()) {
53  vector<Point2f> corners(rhs[1].toVector<Point2f>());
54  cornerSubPix(image, corners, winSize, zeroZone, criteria);
55  plhs[0] = MxArray(corners);
56  }
57  else
58  mexErrMsgIdAndTxt("mexopencv:error", "Invalid corners argument");
59 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
#define CV_32F
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.
void cornerSubPix(InputArray image, InputOutputArray corners, Size winSize, Size zeroZone, TermCriteria criteria)
Global constant definitions.
T c_str(T... args)
cv::Mat toMat() const