我正在尝试重新创建此代码以绘制圆的霍夫变换,但在“圆的霍夫变换”行上出现 TypeError。请帮助我了解为什么我可能会收到该错误。
def fit_circle_houghtransform(vec_x, vec_y):
"""
use hough transform to fit circle:
http://www.janeriksolem.net/2012/08/reading-gauges-detecting-lines-and.html
"""
#load image
im = cv2.imread("gauge1.jpg")
#create a version to draw on and blurred version
draw_im = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
m,n = im.shape
#Hough transform for circles
circles = cv2.HoughCircles(im, cv2.cv.CV_HOUGH_GRADIENT, 2, 10, np.array([]), 20, 60, m/10)[0]
c = circles[0]
cv2.circle(draw_im, (c[0],c[1]), c[2], (0,255,0), 2)
cv2.imshow("circles", im)
cv2.waitKey()
#save imgae
cv2.imwrite("ell.jpg", draw_im)
确切的错误是:
File "fit_circle_houghtransform.py", line 43, in fit_circle_houghtransform
circles = cv2.HoughCircles(im, cv2.cv.CV_HOUGH_GRADIENT, 2, 10, np.array([]), 20, 60, m/10)[0]
TypeError: 'NoneType' object is not subscriptable