-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_main.cpp
70 lines (59 loc) · 2.36 KB
/
old_main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
int main(int argc, char** argv) {
int modifier = atoi(argv[2]);
printf("%s\n", argv[1]);
Mat src=imread(argv[1]);
if (!src.data) {
std::cout << "ERROR:\topening image" <<std::endl;
return -1;
}
// converts the image to hsv so that circle detection is more accurate
Mat hsv_image;
cvtColor(src, hsv_image, COLOR_BGR2HSV);
// high contrast black and white
Mat imgThreshold;
inRange(hsv_image,
Scalar(0, 0, 0),
Scalar(48, 207, 74),
imgThreshold);
// Applies a gaussian blur to the image
GaussianBlur( imgThreshold, imgThreshold, Size(9, 9), 2, 2 );
// fastNlMeansDenoisingColored(imgThreshold, imgThreshold, 10, 10, 7, 21);
vector<Vec3f> circles;
// applies a hough transform to the image
HoughCircles(imgThreshold, circles, CV_HOUGH_GRADIENT,
2, // accumulator resolution (size of image / 2)
100, //minimum dist between two circles
400, // Canny high threshold
10, // minimum number of votes
10, 65); // min and max radius
cout << circles.size() << endl;
cout << "end of test" << endl;
vector<Vec3f>::
const_iterator itc = circles.begin();
int avgRadius = 0;
int i = 0;
// Draws the circles on the source image
while (itc!=circles.end()) {
i++;
circle(src, // src_gray2
Point((*itc)[0], (*itc)[1]), // circle center
(*itc)[2], // circle radius
Scalar(0,0,255), // color
5); // thickness
avgRadius += (*itc)[2];
++itc;
}
avgRadius = avgRadius/i;
cout << avgRadius << endl;
namedWindow("Threshold",CV_WINDOW_AUTOSIZE);
resize(imgThreshold, imgThreshold, Size(src.cols/modifier,src.rows/modifier) ); // resizes it so it fits on our screen
imshow("Threshold",imgThreshold); // displays the source iamge
namedWindow("HSV Color Space",CV_WINDOW_AUTOSIZE);
resize(hsv_image, hsv_image, Size(src.cols/modifier,src.rows/modifier) ); // resizes it so it fits on our screen
imshow("HSV Color Space",hsv_image); // displays the source iamge
namedWindow("Source Image",CV_WINDOW_AUTOSIZE);
resize(src, src, Size(src.cols/modifier,src.rows/modifier) ); // resizes it so it fits on our screen
imshow("Source Image",src); // displays the source iamge
waitKey(0);
return 0;
}