1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import cv2
import numpy as np
dir = r'D:\\img\\'
imgname = 'coins.jpg'
path = dir + imgname
imgOriginal = cv2.imread(path, cv2.IMREAD_COLOR)
gray = imgOriginal[:,:,0]
blur = cv2.GaussianBlur(gray, (7,7), 0)
edges = cv2.Canny(blur, threshold1=100, threshold2=200)
circles = cv2.HoughCircles(blur,cv2.HOUGH_GRADIENT,1,20,param1=200,param2=30, minRadius=0, maxRadius=0)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
cv2.circle(imgOriginal, (i[0], i[1]), i[2], (0, 255, 0), 2)
cv2.circle(imgOriginal, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imshow("Hough Lines", imgOriginal)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print('No Lines found')
|