我正在关注本教程:https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/
我正在摆弄 HoughCircles 的参数(即使是那些你在代码中没有看到的参数,例如:param2),它看起来非常不准确,在我的项目中,你在图片上看到的磁盘将被放置在随机点上,我需要能够检测它们及其颜色。
目前我只能检测到几个圆圈,有时会在没有圆圈的地方绘制一些随机圆圈,所以我有点困惑。
这是使用 openCV 进行圆检测的最佳方法还是有更准确的方法?另外为什么我的代码没有检测到每个圆圈?
初始板: https: //i.stack.imgur.com/Ba6H9.jpg
绘制的圆圈:https://i.stack.imgur.com/3dY4q.jpg
我的代码:
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 …Run Code Online (Sandbox Code Playgroud)