Python图像处理:寻求PIL或相关模块的角点检测帮助
我刚接触图像处理,现在需要对这张图片进行角点检测:
在这张图片中,我需要提取每条线段的起点和终点,或者说是角落的坐标。这只是我项目中的一小部分,但我在这方面没有经验,所以遇到了困难。
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()