A fellow student and I are working on a coin counter via image processing. We used two methods to recognize the coins as circles. On the one hand Connected Components with Stats and on the other Hough Transformation. The advantage of CC w/ Stats is the direct output of all important parameters (e.g. pixel area). However, CC has w/stats weaken with touching coins in the image (center of the coin is not recognized correctly). Hough Transformation doesn't have this problem and easily detects every circle correctly. However, we have no idea how to use the data of the detected objects here. So is there a way to get the data out with another function or is there even a way to generate a hybrid code from CC w/ Stats and Hough Transformation?
import cv2
import numpy as np
import matplotlib.pyplot as plt
image='17.png'
img=cv2.imread(image,1)
img_orig=img.copy()
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img=cv2.GaussianBlur(img,(21,21),cv2.BORDER_DEFAULT)
all_circs=cv2.HoughCircles(img, cv2.HOUGH_GRADIENT,1,500,param1=110,param2=35,minRadius=200,maxRadius=600)
all_circs_rounded=np.uint32(np.around(all_circs))
count = 1
for i in all_circs_rounded[0, :]:
cv2.circle(img_orig,(i[0],i[1],),i[2],(255,0,0),3)
cv2.circle(img_orig,(i[0],i[1],),2,(255,0,0),3)
cv2.putText(img_orig,"Coin"+str(count),(i[0]-70,i[1]+30),cv2.FONT_HERSHEY_SIMPLEX,1.1,(255,0,0),2)
count+=1
print (all_circs_rounded)
print (all_circs_rounded.shape)
print ('I have found ' + str(all_circs_rounded.shape[1]) + ' coins')
plt.rcParams["figure.figsize"]=(16,9)
plt.imshow(img_orig)