mexopencv  0.1
mex interface for opencv library
goodFeaturesToTrack.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>=1 && (nrhs%2)==1 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int maxCorners = 1000;
29  double qualityLevel = 0.01;
30  double minDistance = 2.0;
31  Mat mask;
32  int blockSize = 3;
33  bool useHarrisDetector = false;
34  double k = 0.04;
35  for (int i=1; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key=="MaxCorners")
38  maxCorners = rhs[i+1].toInt();
39  else if (key=="QualityLevel")
40  qualityLevel = rhs[i+1].toDouble();
41  else if (key=="MinDistance")
42  minDistance = rhs[i+1].toDouble();
43  else if (key=="Mask")
44  mask = rhs[i+1].toMat(CV_8U);
45  else if (key=="BlockSize")
46  blockSize = rhs[i+1].toInt();
47  else if (key=="UseHarrisDetector")
48  useHarrisDetector = rhs[i+1].toBool();
49  else if (key=="K")
50  k = rhs[i+1].toDouble();
51  else
52  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
53  }
54 
55  // Process
56  Mat image(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F));
57  vector<Point2f> corners;
58  goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance,
59  mask, blockSize, useHarrisDetector, k);
60  plhs[0] = MxArray(corners);
61 }
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.