Reputation: 43
I use this image
Foto de rupixen.com en Unsplash
I can't understand what the maximum and minimum values of the HoughCircles function in openCV
So that it encloses all the coins. When I set dp to zero an error appears that it cannot be zero, but it is never zero because I add +1 to each trackbar
And when I change the values of the trackbar for example maxR, this error appears:
AttributeError: 'NoneType' object has no attribute 'rint'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/noemi/Escritorio/morphology/hougbarra.py", line 43, in <module>
circles = np.uint16(np.around(circles))
File "<__array_function__ internals>", line 200, in around
File "/home/noemi/Escritorio/morphology/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 3337, in around
return _wrapfunc(a, 'round', decimals=decimals, out=out)
File "/home/noemi/Escritorio/morphology/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 54, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/home/noemi/Escritorio/morphology/venv/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 43, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable rint method
This is the code I'm using
import cv2
import numpy as np
def nada(x):
pass
image = cv2.imread("money.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
filas, columnas, _ = image.shape
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
#Crear la ventana y barras delizantes
cv2.namedWindow("Hough con barras")
cv2.createTrackbar("dp", "Hough con barras", 1, 100, nada)
cv2.createTrackbar("minDist", "Hough con barras", 1, 100, nada)
cv2.createTrackbar("minR", "Hough con barras", 50, 100, nada)
cv2.createTrackbar("maxR", "Hough con barras", 10, 100, nada)
cv2.createTrackbar("param1", "Hough con barras", 100, 100, nada)
cv2.createTrackbar("param2", "Hough con barras", 100, 100, nada)
while True:
img2 = image.copy()
dpd = cv2.getTrackbarPos("dp", "Hough con barras") + 1
minDist = cv2.getTrackbarPos("minDist", "Hough con barras") + 1
param1 = cv2.getTrackbarPos("param1", "Hough con barras") + 1
param2 = cv2.getTrackbarPos("param2", "Hough con barras") + 1
minR = cv2.getTrackbarPos("minR", "Hough con barras") +1
maxR = cv2.getTrackbarPos("maxR", "Hough con barras") + 1
# Find circles with HoughCircles
circles = cv2.HoughCircles(thresh, cv2.HOUGH_GRADIENT, int(dpd), int(columnas / minDist), param1=int(param1), param2=int(param2),
minRadius=int(columnas / minR), maxRadius=int(columnas / maxR))
#Encontrar y dibujar contorna
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
# draw the outer circle
cv2.circle(img2, (i[0], i[1]), i[2], (0, 255, 0), 2)
# draw the center of the circle
cv2.circle(img2, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imshow("Hough con barras", img2)
#cv2.imshow("Contornos", img2)
if cv2.waitKey(1) == ord("s"):
break
cv2.destroyAllWindows()
The trackbars will be useful to review the appropriate values of each parameter but I don't understand how to set the values of each parameter
Upvotes: 0
Views: 66