删除台球桌上的虚假检测到的圆圈

发布于 2025-01-26 08:17:13 字数 1701 浏览 0 评论 0原文

我正在尝试制作一个程序,该程序将接受台球桌的图像并使用OpenCV和Python检测到球。我现在的算法基本上是:1)刻度图像; 2)应用中间模糊; 3)应用高斯模糊; 4)应用cv2.houghcircles()以检测圆圈。

不幸的是,cv2.houghcircles()

当我致电cv2.canny()查看cv2.houghcircles中使用的边缘时,结果包括很多< a href =“ https://i.sstatic.net/w3gbi.jpg” rel =“ nofollow noreferrer”>噪声(由于地毯的颜色/纹理):

”

如何删除错误检测到的圆圈?更改“ param2”的值增加累加器阈值将导致未检测到黑色八球。我想要么考虑1)施加口罩以过滤池以外的所有内容(然后确定来自面具的ROI); 2)应用矩形检测算法来检测池桌; 3)应用信托尝试从图像中确定ROI。

这是原始 image

代码如下:

import cv2

img = cv2.imread("Assets/Setup.jpg", 1)
grayscale_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
median_blur_frame = cv2.medianBlur(grayscale_frame, 5)
gaussian_blur_frame = cv2.GaussianBlur(median_blur_frame, (5, 5), 0)
circles = cv2.HoughCircles(gaussian_blur_frame, cv2.HOUGH_GRADIENT, dp=1, minDist=45, param1=75, param2=14,
                           minRadius=40, maxRadius=45)
for circle in circles[0]:
    print(circle)
    cv2.circle(img, (int(circle[0]), int(circle[1])), int(circle[2]), (255, 255, 255), 5)
cv2.imshow("Frame", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

I am trying to make a program that will accept an image of a pool table and detect balls with OpenCV and Python. My algorithm right now is basically: 1) grayscaling the image; 2) applying median blur; 3) applying Gaussian blur; 4) applying cv2.HoughCircles() to detect circles.

Unfortunately, cv2.HoughCircles() detects random circles in the image:

Pool Table with Poor Circles Detection

When I called cv2.Canny() to see the edges used in cv2.HoughCircles, the results included a lot of noise (due to the color/texture of the carpet):

Canny Edge Detection on Pool Table

How should I remove the false detected circles? Changing the values of "param2" to increase the accumulator threshold will cause the black eight ball to not be detected. I'm thinking of either 1) applying a mask to filter out everything but the pool table (and then determining a ROI from the mask); 2) applying a rectangle detection algorithm to detect the pool table; 3) applying fiducials to try an determine an ROI from the image.

Here is the original image.

The code is below:

import cv2

img = cv2.imread("Assets/Setup.jpg", 1)
grayscale_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
median_blur_frame = cv2.medianBlur(grayscale_frame, 5)
gaussian_blur_frame = cv2.GaussianBlur(median_blur_frame, (5, 5), 0)
circles = cv2.HoughCircles(gaussian_blur_frame, cv2.HOUGH_GRADIENT, dp=1, minDist=45, param1=75, param2=14,
                           minRadius=40, maxRadius=45)
for circle in circles[0]:
    print(circle)
    cv2.circle(img, (int(circle[0]), int(circle[1])), int(circle[2]), (255, 255, 255), 5)
cv2.imshow("Frame", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文