首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试用HoughCircles检测openCV (python)中的所有圆圈

尝试用HoughCircles检测openCV (python)中的所有圆圈
EN

Stack Overflow用户
提问于 2021-01-26 04:07:26
回答 2查看 1.1K关注 0票数 1

我正在学习本教程:https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/

我在玩HoughCircles的参数(甚至那些你在代码ex: HoughCircles中没有看到的参数),它看起来非常innacurate,在我的项目中,您在图片上看到的磁盘将被放置在随机点上,我需要能够检测到它们及其颜色。

目前我只能检测到几个圆圈,有时会有一些随机的圆圈被画在没有圆圈的地方,所以我有点困惑。

这是用openCV进行圆周检测的最佳方法,还是有一种更精确的方法?另外,为什么我的代码没有检测到每个圆圈?

初始板:https://imgur.com/BrPB5Ox

绘制圆:https://imgur.com/dT7k29E

我的代码:

代码语言:javascript
复制
import cv2
import numpy as np


img = cv2.imread('Photos/board.jpg')
output = img.copy()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1.2, 100)
# ensure at least some circles were found
if circles is not None:
    # convert the (x, y) coordinates and radius of the circles to integers
    circles = np.round(circles[0, :]).astype("int")
    # loop over the (x, y) coordinates and radius of the circles
    for (x, y, r) in circles:
        # draw the circle in the output image, then draw a rectangle
        # corresponding to the center of the circle
        cv2.circle(output, (x, y), r, (0, 255, 0), 4)
        cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
    # show the output image
    cv2.imshow("output", np.hstack([img, output]))
    cv2.waitKey(0)

非常感谢。

EN

Stack Overflow用户

发布于 2021-01-26 06:04:54

Hough变换对单色/二值图像的处理效果最好,因此您可能需要使用某种阈值函数对其进行预处理。函数的参数值对于正确识别是非常重要的。

这是用openCV进行圆周检测的最佳方法,还是有一种更精确的方法?另外,为什么我的代码没有检测到每个圆圈?

还有findContours函数shape.html#gadf1ad6a0b82947fa1fe3c3d497f260e0,我认为它更健壮、更通用;您可能想试一试

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65895764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档