Skip to content

Commit ca627a7

Browse files
committed
Added code for hough circle in coin_detection.py file.
1 parent aebbca3 commit ca627a7

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

size-of-objects/coin_detection.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
# load the image, clone it for output, and then convert it to grayscale
66
image_file = '/Users/vaneesh_k/PycharmProjects/Albie_ML/size-of-objects/images/coin.png'
77
image = cv2.imread(image_file)
8-
image = cv2.resize(image,(800,800))
8+
image = cv2.resize(image, (800, 800))
99
output = image.copy()
1010
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
11+
# mask =
1112

13+
cv2.imshow('mask',gray)
1214
# detect circles in the image
13-
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 2, 1,minRadius=5,maxRadius=10)
14-
print('FOund some circles')
15+
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 4.0, 100, 100.0, 30.0, 20, 200)
16+
print('Found some circles')
1517
# ensure at least some circles were found
1618
if circles is not None:
17-
print('Found circle')
18-
# convert the (x, y) coordinates and radius of the circles to integers
19-
circles = np.round(circles[0, :]).astype("int")
19+
print('filterd circles')
20+
# convert the (x, y) coordinates and radius of the circles to integers
21+
circles = np.round(circles[0, :]).astype("int")
2022

23+
# loop over the (x, y) coordinates and radius of the circles
24+
for (x, y, r) in circles:
25+
# draw the circle in the output image, then draw a rectangle
26+
# corresponding to the center of the circle
27+
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
28+
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
2129

22-
# loop over the (x, y) coordinates and radius of the circles
23-
for (x, y, r) in circles:
24-
# draw the circle in the output image, then draw a rectangle
25-
# corresponding to the center of the circle
26-
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
27-
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
28-
29-
# show the output image
30-
cv2.imshow("output", np.hstack([image, output]))
31-
cv2.waitKey(0)
30+
# show the output image
31+
cv2.imshow("output", np.hstack([image, output]))
32+
cv2.waitKey(0)

size-of-objects/images/coin.png

9.15 MB
Loading

size-of-objects/object_size.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def midpoint(ptA, ptB):
1212

1313

1414

15-
image = '/Users/vaneesh_k/PycharmProjects/Albie_ML/size-of-objects/images/card2.png'
15+
image = '/Users/vaneesh_k/PycharmProjects/Albie_ML/size-of-objects/images/coin.png'
1616
# load the image, convert it to grayscale, and blur it slightly
1717
image = cv2.imread(image)
1818
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@@ -40,7 +40,7 @@ def midpoint(ptA, ptB):
4040
# loop over the contours individually
4141
for c in cnts:
4242
# if the contour is not sufficiently large, ignore it
43-
if not 150 <= cv2.contourArea(c) <= 200:
43+
if not 20 <= cv2.contourArea(c) <= 150:
4444
continue
4545

4646
# compute the rotated bounding box of the contour

0 commit comments

Comments
 (0)