在我将霍夫圆合并到我正在编写的跟踪程序的主代码中之前,我试图弄清楚霍夫圆,但我似乎只能从圆中得到None
。我使用孟加拉国旗作为我的图像,因为它很简单,也很容易检测。以下是我的代码:
import numpy as np
import cv2
img = cv2.imread('Capture.PNG')
grayput = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(grayput, cv2.cv.CV_HOUGH_GRADIENT, 1, 20, param1 =50, param2 =10, minRadius=10, maxRadius=40)
print (circles)
# need circles
if circles is not None:
# convert the coord. to integers
circles = np.round(circles[0, :]).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circles:
# draw the circle in the output image
cv2.circle(img, (x, y), r, (0, 0, 0), 4)
cv2.imwrite("image.PNG",img)
2条答案
按热度按时间ajsxfq5m1#
通过反复试验,我能够将param 1和param 2操作到cv2.HoughCircle输出返回numpy. ndarray的位置。如果HoughCircle param 1和/或param 2阈值未满足,则似乎返回None。
kd3sttzy2#
下面的代码将为您提供 non-None 圆:
实际上,输出为:
注意:代码段使用以下内容作为其输入图像: