【问题标题】:Hough Circle detction AttributeError: 'NoneType' object has no attribute 'rint'霍夫圆检测 AttributeError:“NoneType”对象没有属性“rint”
【发布时间】:2020-06-21 09:23:35
【问题描述】:

我正在尝试在 open cv2 中使用 Houghcircle 检测这个圆圈,但出现错误。

下面是我的代码

1

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 尝试: ---> 56 返回 getattr(obj, method)(*args, **kwds) 57

AttributeError: 'NoneType' 对象没有属性 'round'

在处理上述异常的过程中,又发生了一个异常:

AttributeError Traceback(最近一次调用最后一次) 在 ----> 1 ch = np.uint16(np.around(ch)) #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, out=out) 3008 第3009章

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 64 # 像“熊猫”这样的下游库。 65 除了(AttributeError,TypeError): ---> 66 返回 _wrapit(obj, 方法, *args, **kwds) 67 68

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds) 44 属性错误除外: 45 换行 = 无 ---> 46 结果 = getattr(asarray(obj), 方法)(*args, **kwds) 47 如果换行: 48 if not isinstance(result, mu.ndarray):

AttributeError: 'NoneType' 对象没有属性 'rint'

【问题讨论】:

  • ch in [2] 未定义。您正在 [1] 中创建 chh
  • 对不起,如果我在第二个代码中插入“chh”,我仍然会得到同样的错误

标签: python image numpy opencv image-processing


【解决方案1】:

这是一个使用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()

【讨论】:

    猜你喜欢
    • 2019-04-14
    • 2022-07-17
    • 2020-09-29
    • 1970-01-01
    • 2019-01-01
    • 2021-12-26
    • 2019-07-23
    • 2018-05-13
    • 2020-09-07
    相关资源
    最近更新 更多