使用OpenCV HoughCirlces时,我无法访问检测到的圆数

2024-05-16 09:37:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中的一个.png图像上使用了houghcirles。当我运行代码时:

def circleCheck(self, imPath):
    image = cv2.imread(imPath)
    image = cv2.medianBlur(image, 5)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)
    self.alphaCount = len(circles)

其中alphaCount应该包含图像中的圈数,我得到 TypeError: object of type 'NoneType' has no len() 我不知道为什么as circles应该返回一个长度为0的列表。任何帮助都将不胜感激。你知道吗


Tags: 代码图像imageselflenpngdefcv2