mexopencv  0.1
mex interface for opencv library
HoughLinesP.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  double rho = 1;
29  double theta = CV_PI/180;
30  int threshold = 80;
31  double minLineLength = 0;
32  double maxLineGap = 0;
33  for (int i=1; i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key=="Rho")
36  rho = rhs[i+1].toDouble();
37  else if (key=="Theta")
38  theta = rhs[i+1].toDouble();
39  else if (key=="Threshold")
40  threshold = rhs[i+1].toInt();
41  else if (key=="MinLineLength")
42  minLineLength = rhs[i+1].toDouble();
43  else if (key=="MaxLineGap")
44  maxLineGap = rhs[i+1].toDouble();
45  else
46  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
47  }
48 
49  // Process
50  Mat image(rhs[0].toMat(CV_8U));
51  vector<Vec4i> lines;
52  HoughLinesP(image, lines, rho, theta, threshold, minLineLength, maxLineGap);
53  plhs[0] = MxArray(lines);
54 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: HoughLinesP.cpp:19
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.