【发布时间】:2021-01-26 04:07:26
【问题描述】:
我正在关注本教程:https://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/
我在玩 HoughCircles 的参数(即使是你在代码中看不到的参数,例如:param2),看起来很不准确,在我的项目中,你在图片上看到的磁盘将被放置在随机点上我需要能够检测到它们和它们的颜色。
目前我只能检测到几个圆圈,有时会在没有圆圈的地方绘制一些随机圆圈,所以我有点困惑。
这是使用 openCV 进行圆检测的最佳方法还是有更准确的方法? 另外为什么我的代码没有检测到每个圆圈?
我的代码:
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)
非常感谢。
【问题讨论】:
标签: python opencv computer-vision detection