gpt4 book ai didi

python - 霍夫圆检测AttributeError : 'NoneType' object has no attribute 'rint'

转载 作者:行者123 更新时间:2023-12-02 07:02:20 28 4
gpt4 key购买 nike

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

enter image description here

下面是我的代码

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

解释将非常有值(value)。亲切的问候。

完整错误:

AttributeError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 55 try: ---> 56 return getattr(obj, method)(*args, **kwds) 57

AttributeError: 'NoneType' object has no attribute 'round'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) in ----> 1 ch = np.uint16(np.around(ch)) #error appears to come from here

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 # a downstream library like 'pandas'. 65 except (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' object has no attribute '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()

关于python - 霍夫圆检测AttributeError : 'NoneType' object has no attribute 'rint' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60601374/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com