mexopencv  0.1
mex interface for opencv library
HoughCircles.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
14 const ConstMap<string,int> HoughModesMap = ConstMap<string,int>
15  ("Standard", cv::HOUGH_STANDARD)
16  ("Probabilistic", cv::HOUGH_PROBABILISTIC)
17  ("MultiScale", cv::HOUGH_MULTI_SCALE)
18  ("Gradient", cv::HOUGH_GRADIENT);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  Mat image(rhs[0].toMat(CV_8U));
37 
38  // Option processing
39  int method = cv::HOUGH_GRADIENT;
40  double dp = 1;
41  double minDist = image.rows/8;
42  double param1 = 100;
43  double param2 = 100;
44  int minRadius = 0;
45  int maxRadius = 0;
46  for (int i=1; i<nrhs; i+=2) {
47  string key(rhs[i].toString());
48  if (key=="Method")
49  method = HoughModesMap[rhs[i+1].toString()];
50  else if (key=="DP")
51  dp = rhs[i+1].toDouble();
52  else if (key=="MinDist")
53  minDist = rhs[i+1].toDouble();
54  else if (key=="Param1")
55  param1 = rhs[i+1].toDouble();
56  else if (key=="Param2")
57  param2 = rhs[i+1].toDouble();
58  else if (key=="MinRadius")
59  minRadius = rhs[i+1].toInt();
60  else if (key=="MaxRadius")
61  maxRadius = rhs[i+1].toInt();
62  else
63  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
64  }
65 
66  // Process
67  vector<Vec3f> circles;
68  HoughCircles(image, circles, method, dp, minDist,
69  param1, param2, minRadius, maxRadius);
70  plhs[0] = MxArray(circles);
71 }
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927