mexopencv  3.4.1
MEX interface for OpenCV library
goodFeaturesToTrack.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>=1 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  int maxCorners = 1000;
30  double qualityLevel = 0.01;
31  double minDistance = 2.0;
32  Mat mask;
33  int blockSize = 3;
34  int gradientSize = 3;
35  bool useHarrisDetector = false;
36  double k = 0.04;
37  for (int i=1; i<nrhs; i+=2) {
38  string key(rhs[i].toString());
39  if (key == "MaxCorners")
40  maxCorners = rhs[i+1].toInt();
41  else if (key == "QualityLevel")
42  qualityLevel = rhs[i+1].toDouble();
43  else if (key == "MinDistance")
44  minDistance = rhs[i+1].toDouble();
45  else if (key == "Mask")
46  mask = rhs[i+1].toMat(CV_8U);
47  else if (key == "BlockSize")
48  blockSize = rhs[i+1].toInt();
49  else if (key == "GradientSize")
50  gradientSize = rhs[i+1].toInt();
51  else if (key == "UseHarrisDetector")
52  useHarrisDetector = rhs[i+1].toBool();
53  else if (key == "K")
54  k = rhs[i+1].toDouble();
55  else
56  mexErrMsgIdAndTxt("mexopencv:error",
57  "Unrecognized option %s", key.c_str());
58  }
59 
60  // Process
61  Mat image(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F));
62  vector<Point2f> corners;
63  goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance,
64  mask, blockSize, gradientSize, useHarrisDetector, k);
65  plhs[0] = MxArray(corners);
66 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#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.
Global constant definitions.
T c_str(T... args)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void goodFeaturesToTrack(InputArray image, OutputArray corners, int maxCorners, double qualityLevel, double minDistance, InputArray mask=noArray(), int blockSize=3, bool useHarrisDetector=false, double k=0.04)
cv::Mat toMat() const