Last answered:

04 Jan 2024

Posted on:

04 Jan 2024

0

i'm getting this result, even though i did the same steps

 RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
[nan, nan, nan, nan, nan, nan, nan, nan]

1 answers ( 0 marked as helpful)
Posted on:

04 Jan 2024

0

import numpy as np
import cv2 

def av_pix(img,circles,size):
    av_value = []
    for coords in circles[0,:]:
        col = np.mean(img[coords[1]+size:coords[1]-size,coords[0]+size:coords[0]-size])
        av_value.append(col)
    return av_value

def get_radius(circles):
    radius=[]
    for coords in circles[0,:]:
        radius.append(coords[2])
    return radius



img = cv2.imread('capstone_coins.png',cv2.IMREAD_GRAYSCALE)
original_image = cv2.imread('capstone_coins.png',1)
img = cv2.GaussianBlur(img,(5,5),0 )
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,0.9,120,param1=50,param2=27,minRadius=60,maxRadius=120)

circles = np.uint16(np.around(circles))
count = 1 
for i in circles[0, :]:
    center = (i[0], i[1])
    # circle center
    cv2.circle(original_image, center, 2, (0, 255, 0), 2)
    # circle outline
    radius_2 = i[2]
    cv2.circle(original_image, center, radius_2, (255, 0, 0), 3)
    cv2.putText(original_image,str(count),center,cv2.FONT_HERSHEY_SIMPLEX,2,(0,0,0),2)
    count +=1

radii = get_radius(circles)
print(radii)

bright_values = av_pix(img,circles,20)
print(bright_values)

# cv2.imshow('detected coins',original_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

Submit an answer