【发布时间】:2021-01-21 13:47:07
【问题描述】:
我需要检测这些曲线上的点,特别是我需要从左侧开始的两个点之一在图像上的位置:
我试图像这样检测霍夫点:
import cv2
import numpy as np
# detect circles in the image
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
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([image, output]))
cv2.waitKey(0)
但它没有得到正确的点,我想这是因为这些点是沿着两条曲线定位的。有没有办法检测曲线上的点?
【问题讨论】:
-
如果您知道这两种颜色,则对图像进行颜色阈值处理,并侵蚀生成的蒙版,使点保留,但线消失。在剩余点上找到轮廓。对两种颜色都这样做。对于重叠点的“背景”彩色线(这里:红色),这种方法可能会失败。如果是这样,请使用已从“前景”彩色线(此处:蓝色)获得的一些信息。
-
一种非常非常简单的起点方法:按列扫描图像,并在所需颜色的第一个像素处停止。基本但防弹。
-
@HansHirse 我跟着你的步骤,它就像一个魅力。谢谢!我用结果发布了答案