-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circlefind.cpp
39 lines (29 loc) · 924 Bytes
/
Circlefind.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "pch.h"
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
using namespace std;
int main()
{
Mat input = imread("coins5.jpg");
Mat gray_input;
cvtColor(input, gray_input, CV_BGR2GRAY);
Mat blur, thres, canny, output;
vector<Vec3f> circles;
GaussianBlur(gray_input, blur, Size(5, 5), 2);
threshold(blur, thres, 225, 255, THRESH_BINARY);
Canny(blur, canny, 1, 255);
HoughCircles(canny, circles, CV_HOUGH_GRADIENT, 1, 80, 200, 15, 42, 120);
for (size_t i = 0; i < circles.size(); i++) {
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
circle(input, center, 3, Scalar(0, 255, 0), -1);
circle(input, center, radius, Scalar(0, 0, 255), 3);
}
imshow("input", input);
imshow("thres", thres);
imshow("canny", canny);
waitKey();
}