mexopencv  3.4.1
MEX interface for OpenCV library
HoughCircles.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 
13 namespace {
16  ("Standard", cv::HOUGH_STANDARD)
17  ("Probabilistic", cv::HOUGH_PROBABILISTIC)
18  ("MultiScale", cv::HOUGH_MULTI_SCALE)
19  ("Gradient", cv::HOUGH_GRADIENT);
20 }
21 
29 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
30 {
31  // Check the number of arguments
32  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
33 
34  // Argument vector
35  vector<MxArray> rhs(prhs, prhs+nrhs);
36 
37  Mat image(rhs[0].toMat(CV_8U));
38 
39  // Option processing
40  int method = cv::HOUGH_GRADIENT;
41  double dp = 1;
42  double minDist = image.rows/8;
43  double param1 = 100; // cannyThreshold
44  double param2 = 100; // accumulatorThreshold
45  int minRadius = 0;
46  int maxRadius = 0;
47  for (int i=1; i<nrhs; i+=2) {
48  string key(rhs[i].toString());
49  if (key == "Method")
50  method = HoughModesMap[rhs[i+1].toString()];
51  else if (key == "DP")
52  dp = rhs[i+1].toDouble();
53  else if (key == "MinDist")
54  minDist = rhs[i+1].toDouble();
55  else if (key == "Param1")
56  param1 = rhs[i+1].toDouble();
57  else if (key == "Param2")
58  param2 = rhs[i+1].toDouble();
59  else if (key == "MinRadius")
60  minRadius = rhs[i+1].toInt();
61  else if (key == "MaxRadius")
62  maxRadius = rhs[i+1].toInt();
63  else
64  mexErrMsgIdAndTxt("mexopencv:error",
65  "Unrecognized option %s", key.c_str());
66  }
67 
68  // Process
69  vector<Vec3f> circles;
70  HoughCircles(image, circles, method, dp, minDist,
71  param1, param2, minRadius, maxRadius);
72  plhs[0] = MxArray(circles);
73 }
HOUGH_STANDARD
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
HOUGH_MULTI_SCALE
HOUGH_PROBABILISTIC
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...
void HoughCircles(InputArray image, OutputArray circles, int method, double dp, double minDist, double param1=100, double param2=100, int minRadius=0, int maxRadius=0)
const ConstMap< string, int > HoughModesMap
Hough transform modes for option processing.
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
T c_str(T... args)
HOUGH_GRADIENT
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const