霍夫圆环检测AttributeError:'NoneType'对象没有属性'rint'

时间:2020-03-09 13:15:09

标签: python image numpy opencv image-processing

我正在尝试在打开的cv2中使用Houghcircle检测到该圆,但是出现错误。

enter image description here

下面是我的代码

1

function WideCharToMultiByte_ToInnoString(CodePage: Cardinal; dwFlags: Cardinal; lpWideCharStr: PWideChar; cchWideChar: Cardinal; lpMultiByteStr: String; cbMultiByte: Cardinal; lpDefaultChar: Cardinal; lpUsedDefaultChar: Cardinal): Integer;
external 'WideCharToMultiByte@kernel32.dll stdcall';

{ Later on: Instead of calling lstrcpyW_ToInnoString, use this:
  Note: The first parameter 0 stands for CP_ACP (current ANSI code page), and the
  string lengths are increased by 1 to include the null terminator }
WideCharToMultiByte_ToInnoString(0, 0, returnedPointer, stringLength + 1, innoString, stringLength + 1, 0, 0);

[2]

chh = cv2.HoughCircles(crr, cv2.HOUGH_GRADIENT, 1,minDist = 50, param1 =200, 
param2 = 18, minRadius = 20, maxRadius =60)

假设1找到了圆,而[2]则将其转换成数组,怀疑是ch = np.uint16(np.around(ch)) #error appears to come from here

一个解释将非常有价值。 此致。

完全错误:

AttributeError跟踪(最近一次呼叫最近) _wrapfunc中的C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py(obj,method,* args,** kwds) 55尝试: ---> 56 return getattr(obj,method)(* args,** kwds) 57

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

在处理上述异常期间,发生了另一个异常:

AttributeError跟踪(最近一次呼叫最近) 在 ----> 1 ch = np.uint16(np.around(ch))#错误似乎是从这里来的

C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py在周围(a,小数,出) 3005 3006“”“ -> 3007 return _wrapfunc(a,'round',十进制=小数,out = out) 3008 3009

_wrapfunc中的C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py(obj,method,* args,** kwds) 64#下游库,例如“ pandas”。 65(AttributeError,TypeError)除外: ---> 66 return _wrapit(obj,method,* args,** kwds) 67 68

_wrapit中的

C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py(obj,method,* args,** kwds) 44除了AttributeError: 45包=无 ---> 46结果= getattr(asarray(obj),method)(* args,** kwds) 47如果换行: 48如果不是isinstance(result,mu.ndarray):

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

1 个答案:

答案 0 :(得分: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()