mexopencv  0.1
mex interface for opencv library
cornerHarris.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 blockSize = 5;
29  int ksize = 3;
30  double k = 0.04;
31  int borderType = cv::BORDER_DEFAULT;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key=="BlockSize")
35  blockSize = rhs[i+1].toInt();
36  else if (key=="KSize")
37  ksize = rhs[i+1].toInt();
38  else if (key=="K")
39  k = rhs[i+1].toDouble();
40  else if (key=="BorderType")
41  borderType = BorderType[rhs[i+1].toString()];
42  else
43  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
44  }
45 
46  // Process
47  Mat src(rhs[0].toMat(rhs[0].isUint8() ? CV_8U : CV_32F)), dst;
48  cornerHarris(src, dst, blockSize, ksize, k, borderType);
49  plhs[0] = MxArray(dst);
50 }
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
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.