我最近开始使用HoughCirlces学习圆检测,并希望通过将参数转换为跟踪条来更深入地探索这些参数。一切运行正常,直到参数变得太大,我得到以下错误:
Traceback (most recent call last):
File "C:\Users\Benji\Documents\Python Scripts\HoughParameters.py", line 55, in <module>
Circles()
File "C:\Users\Benji\Documents\Python Scripts\HoughParameters.py", line 43, in Circles
circles = np.uint16(np.around(circles))
File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 2621, in around
return _wrapit(a, 'round', decimals, out)
File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 45, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
AttributeError: 'NoneType' object has no attribute 'rint'
轨道栏限制是根据HoughCircles可接受的设置来设置的,因此我猜测轨道栏的功能如何,我不太了解。代码如下:
import cv2
import video
import sys
import numpy as np
def nothing(x):
pass
def Circles():
cv2.namedWindow('Circles')
cv2.namedWindow('parameters')
cv2.createTrackbar('dp', 'parameters', 1, 20, nothing)
cv2.createTrackbar('minDist', 'parameters', 10, 700, nothing)
cv2.createTrackbar('CannyParam', 'parameters', 1, 300, nothing)
cv2.createTrackbar('AccumulatorThrs', 'parameters', 1, 100, nothing)
cv2.createTrackbar('minRadius', 'parameters', 1, 50, nothing)
cv2.createTrackbar('maxRadius', 'parameters', 51, 700, nothing)
image = cv2.imread('openCVlogo.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
gray = gray[:,:,2]
#cv2.imshow('ImageGray', gray)
while True:
dp = cv2.getTrackbarPos('dp', 'parameters')
minDist = cv2.getTrackbarPos('minDist', 'parameters')
CannyParam = cv2.getTrackbarPos('CannyParam', 'parameters')
AccumulatorThrs = cv2.getTrackbarPos('AccumulatorThrs', 'parameters')
minRadius = cv2.getTrackbarPos('minRadius', 'parameters')
maxRadius = cv2.getTrackbarPos('maxRadius', 'parameters')
circles = cv2.HoughCircles(gray,cv2.cv.CV_HOUGH_GRADIENT,dp,minDist,CannyParam,AccumulatorThrs,minRadius,maxRadius)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(image,(i[0],i[1]),i[2],(0,255,0),2)
cv2.circle(image,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('Circles', image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
Circles()
我使用OpenCV logo作为测试图片。我上传了一个屏幕截图,但不幸的是这是我的第一篇文章,我不允许这样做。任何帮助将不胜感激!即使只是谷歌的一条跳跃之路。