python - 霍夫圆检测 AttributeError:“NoneType”对象没有属性“rint”
问题描述
我正在尝试在 open cv2 中使用 Houghcircle 检测这个圆圈,但出现错误。
下面是我的代码
chh = cv2.HoughCircles(crr, cv2.HOUGH_GRADIENT, 1,minDist = 50, param1 =200,
param2 = 18, minRadius = 20, maxRadius =60)
[2]
ch = np.uint16(np.around(ch)) #error appears to come from here
我假设1找到了圆圈,而 [2] 将其转换为数组,我怀疑np.around
。
一个解释将非常有价值。亲切的问候。
完整错误:
AttributeError Traceback(最近一次调用最后一次)C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 55 try: ---> 56返回 getattr(obj, 方法)(*args, **kwds) 57
AttributeError:“NoneType”对象没有属性“round”
在处理上述异常的过程中,又出现了一个异常:
----> 1 ch = np.uint16(np.around(ch)) #error 中的 AttributeError Traceback (last recent call last) #error 似乎来自这里
C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in around(a, decimals, out) 3005 3006 """ -> 3007 return _wrapfunc(a, 'round', decimals=decimals,出=出)3008 3009
C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 64 # 像'pandas'这样的下游库。65 除了 (AttributeError, TypeError): ---> 66 return _wrapit(obj, method, *args, **kwds) 67 68
C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds) 44 except AttributeError: 45 wrap = None ---> 46 result = getattr (asarray(obj), method)(*args, **kwds) 47 if wrap: 48 if not isinstance(result, mu.ndarray):
AttributeError:“NoneType”对象没有属性“rint”
解决方案
这是一个简单的例子来执行圆检测cv2.HoughCircles
import cv2
import numpy as np
# Load image, grayscale, Otsu's threshold
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Find circles with HoughCircles
circles = cv2.HoughCircles(thresh, cv2.HOUGH_GRADIENT, 1, minDist=150, param1=200, param2=18, minRadius=20)
# Draw circles
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x,y,r) in circles:
cv2.circle(image, (x,y), r, (36,255,12), 3)
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()
推荐阅读
- jquery - 将元素的属性值设置为存储在 jQuery 变量中的数值
- android - 如何从android中的另一个活动返回到活动的特定片段
- python - 网页抓取的性能改进?
- algorithm - 具有嵌套循环的函数的时间复杂度
- php - 添加点击查看定价表中的详细信息
- r - R susbet 匹配“ANY”(联合)
- python - 为 2 个用户而不是 1 个用户重复此登录系统的最佳方法是什么?
- mule4 - Mule 4:流:如何检查负载是否是 Mule 4 中的流?
- git - Github Pages / Github 自动数据推送策略
- c# - 使用异步/等待问题更新和检索数据