1 #include "opencv2/imgcodecs.hpp"
2 #include "opencv2/highgui/highgui.hpp"
3 #include "opencv2/imgproc/imgproc.hpp"
12 cout << "\nThis program demonstrates circle finding with the Hough transform.\n"
14 "./houghcircles <image_name>, Default is pic1.png\n" << endl;
17 int main(int argc, char** argv)
19 const char* filename = argc >= 2 ? argv[1] : "board.jpg";
21 Mat img = imread(filename, 0);
25 cout << "can not open " << filename << endl;
30 medianBlur(img, img, 5);
31 cvtColor(img, cimg, COLOR_GRAY2BGR);
33 vector<Vec3f> circles;
34 HoughCircles(img, circles, HOUGH_GRADIENT, 1, 10,
35 100, 30, 1, 30 // change the last two parameters
36 // (min_radius & max_radius) to detect larger circles
38 for( size_t i = 0; i < circles.size(); i++ )
41 circle( cimg, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA);
42 circle( cimg, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA);
45 imshow("detected circles", cimg);