【问题标题】:How to accurately detect the positions of hollow circles (rings) with OpenCV Python?如何使用 OpenCV Python 准确检测空心圆(环)的位置?
【发布时间】:2022-06-15 02:14:31
【问题描述】:

我想确定此视频静止图像中注射器尖端的中心位置。尖端名义上是圆形的并且具有已知的大小和数量。

我目前在提示上涂上红色墨水,以便更容易检测到。我很高兴不必这样做,但我认为如果没有它,检测将非常困难。有人喜欢挑战吗?

我开始尝试 SimpleBlobDetector,因为它有一些不错的过滤功能。我想不通的一件事是如何让 SimpleBlobDetector 检测空心圆(环)?

然后我尝试了canny + hough,但是圆圈检测太不稳定,位置跳来跳去。

我目前正在使用 findContours + minEnclosureCircle,它工作正常,但仍然很不稳定。 面具看起来像这样:

而结果,你可以看到准确率不是很高:

我简要地查看了 RANSAC,但找不到可以检测多个圆的 Python 示例,而且边缘检测很棘手。

我当前的代码:

# https://stackoverflow.com/questions/32522989/opencv-better-detection-of-red-color
frame_inv = ~frame0
# Convert BGR to HSV
hsv = cv2.cvtColor(frame_inv, cv2.COLOR_BGR2HSV)
blur = cv2.GaussianBlur(hsv, (5, 5), 0)
# define range of color in HSV
lower_red = np.array([90 - 10, 70, 50])
upper_red = np.array([90 + 10, 255, 255])
# Threshold the HSV image to get only red colors
mask = cv2.inRange(hsv, lower_red, upper_red)
# cv2.imshow('Mask', mask)
kernel = np.ones((5, 5), np.uint8)
dilate = cv2.dilate(mask, kernel)
# cv2.imshow('Dilate', dilate)
contours = cv2.findContours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0]

tipXY = []
for c in contours:
    area = cv2.contourArea(c)
    if area > 200:
        (x, y), r = cv2.minEnclosingCircle(c)
        center = (int(x), int(y))
        r = int(r)
        shift = 2
        factor = 2 ** shift
        cv2.circle(frame0, (int(round((x) * factor)), int(round((y) * factor))),
                       int(round(10 * factor)), (0, 255, 0), 2, shift=shift)
        tipXY.append(center)

有什么提高检测精度的建议吗?

【问题讨论】:

  • Hough circles 相当不错。使用您当前的照明设置,如果不将它们标记为红色,可能很难找到这些提示。如果您能以某种方式从未标记的提示中获得更多对比度,也许您可​​以做一些边缘增强/检测技术。

标签: python opencv image-processing


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-03
  • 2020-01-17
  • 1970-01-01
相关资源
最近更新 更多