Python图像处理:寻求PIL或相关模块的角点检测帮助

8 投票
5 回答
4450 浏览
提问于 2025-04-17 09:18

我刚接触图像处理,现在需要对这张图片进行角点检测:

enter image description here

在这张图片中,我需要提取每条线段的起点和终点,或者说是角落的坐标。这只是我项目中的一小部分,但我在这方面没有经验,所以遇到了困难。

5 个回答

2

这个被接受的答案并没有找到图像中的所有角落。

通过使用哈里斯角点检测,我们可以找到所有可能的角落。因为提问者选择的模块没有限制,所以我决定使用OpenCV库来进行以下操作。

结果:

在这里输入图片描述

图像中的每一个角落都被正确识别出来了。

这个页面提供了算法和代码的详细信息。

2

我建议你使用OpenCV,这个工具里有哈里斯角点检测器和施-汤马斯角点检测器。

28

这里有一个解决方案,使用的是scikit-image这个库:

from skimage import io, color, morphology
from scipy.signal import convolve2d
import numpy as np
import matplotlib.pyplot as plt

img = color.rgb2gray(io.imread('6EnOn.png'))

# Reduce all lines to one pixel thickness
snakes = morphology.skeletonize(img < 1)

# Find pixels with only one neighbor
corners = convolve2d(snakes, [[1, 1, 1],
                              [1, 0, 1],
                              [1, 1, 1]], mode='same') == 1
corners = corners & snakes

# Those are the start and end positions of the segments
y, x = np.where(corners)

plt.imshow(img, cmap=plt.cm.gray, interpolation='nearest')
plt.scatter(x, y)
plt.axis('off')
plt.show()

线段的角点

撰写回答