简体   繁体   English

Python图像处理:最好在PIL或任何相关模块中进行角点检测所需的帮助

[英]Python image processing : Help needed for corner detection in preferably PIL or any relevant module

I'm new to image processing and got to do corner detection for this image: 我是图像处理的新手,必须对此图像进行拐角检测: 在此处输入图片说明

In this image, I need to extract the starting and end points of each line segment or the coordinates of the corners. 在此图像中,我需要提取每个线段的起点和终点或角的坐标。 This is just a small part in my project and I'm stuck on this because I've no experience in image processing. 这只是我项目中的一小部分,我坚持这样做是因为我没有图像处理经验。

Here's a solution, using scikit-image : 这是使用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()

线段的角

The accepted answer does not find ALL the corners in the image. 接受的答案未找到图像中的所有角。

Using Harris corner detection , one can find all the possible corners. 使用Harris角点检测 ,可以找到所有可能的角点。 Since OP's choice of modules is not restricted, I chose to perform the following using the OpenCV library. 由于OP的模块选择不受限制,因此我选择使用OpenCV库执行以下操作。

RESULT: 结果:

在此处输入图片说明

Every single corner present in the image is identified correctly. 正确识别图像中存在的每个角。

THIS PAGE provides details of the algorithm and the code. 此页面提供了算法和代码的详细信息。

我建议使用Harris拐角检测器和Shi-Tomasi拐角检测器随附的OpenCV

I don't know whether I understand the question correctly, but I think a low efficiency way to do it is to scan through each pixel and check the 4 directions around that pixel. 我不知道我是否正确理解了这个问题,但是我认为这样做的低效率方法是扫描每个像素并检查该像素周围的4个方向。 If 2 non-opposite directions (ie up & left or up & right etc.) are coloured, then it is a corner. 如果2个非相反的方向(即,向上和向左或向上和向右等)上色,则为角。

Hope this helps. 希望这可以帮助。

This is a bit of a shot in the dark, but I'd assume that you could parse the png header to retrieve the width/height of the image (take a look at this RFC for png details ). 这是在黑暗中的镜头,但我假设您可以解析png标头以检索图像的宽度/高度(请参阅此RFC了解png细节 )。 Combine this with the bit depth of the image and you should be able to determine where each corner is with simple math. 将其与图像的位深度结合起来,您应该能够通过简单的数学运算确定每个角的位置。 Once you've found the corner, you should be able to follow the line using a simple algorithm checking neighboring pixel data. 找到角点后,您应该能够使用一种检查相邻像素数据的简单算法沿线行驶。

This also sounds like homework. 这听起来也像作业。 If so, you should tag it as such. 如果是这样,则应该这样标记它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM