如何在一条直线上获得曲线上的点?

3
我想检测线条上的所有拐角、起点和终点。我可以检测起点和终点,但是曲线无法检测到。这是我的代码。
from scipy.ndimage import generic_filter

def lineEnds(P):
    return 255 * ((P[4]==255) and np.sum(P)==510)

 image = cv2.imread("./dataset/test.jpg" , cv2.COLOR_RGB2GRAY)
 result = generic_filter(image , lineEnds, (3, 3))

图片 = 在此输入图片描述

结果 = 在此输入图片描述

1个回答

3

你可以使用OpenCV来检测角点。

import cv2

image = cv2.imread('./test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect corners in the image
corners = cv2.goodFeaturesToTrack(gray, 500, qualityLevel=0.01, minDistance=20)

for c in corners:
    x, y = c.reshape(2)
    print(x, y)
    # draw a circle around the detected corner
    cv2.circle(image, (x, y), radius=4, color=(0, 255, 120), thickness=2)

cv2.imshow("Result", image)
cv2.waitKey(0)

结果:

输入图像

更多详情请查看以下文档:

Shi-Tomasi角点检测器

Harris角点检测


在这个例子中,goodFeaturesToTrack 是一把铲子,用作引导飞机降落的工具。它可能会起作用,但并不是真正打算用于那种方式。 - Croolman
@Croolman,我很高兴能得到另一个答案。 - MohammadHosseinZiyaaddini

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接