我想检测图像中间的垂直曲线。你知道怎么做吗?我想用线将左侧和右侧分开。我应该使用什么功能或过滤器?非常感谢您提出如何检测线路的想法。
图片链接如下:
顺便说一句:我在 Python 中使用 OpenCV 库。
最佳答案
抱歉,我不太了解 OpenCV。所以这里是如何做的概述。我还使用 Imagemagick 和 Python Wand 代码展示代码。请注意,我保存了中间图像以显示步骤。
Read the image
Blur it some
Threshold is to binary
Do connected components processing to remove all small regions (see contours or blobs in OpenCV)
Use morphology open and close to smooth the edges
Extract an edge outline of the transition between white and black (there are many edge operators: laplacian, gradients, canny, etc)
输入:
convert img.jpg -blur 0x1 -threshold 9% -type bilevel +write threshold.png \
-define connected-components:mean-color=true \
-define connected-components:area-threshold=10000 \
-connected-components 4 +write ccl.png \
-morphology open disk:5 \
-morphology close disk:5 +write smooth.png \
-morphology edge diamond:1 \
result.png
阈值:
连接组件:
平滑:
结果:
这是使用 Python Wand 0.5.6(目前正在开发中)和 Imagemagick 7.0.8.56 的等效代码
#!/bin/python3.7
from wand.image import Image
from wand.display import display
with Image(filename='curve.jpg') as img:
img.blur(radius=0, sigma=1)
img.threshold(threshold=0.09)
img.connected_components(connectivity=4, area_threshold=1000, mean_color=True)
img.morphology(method='open', kernel='disk:5')
img.morphology(method='close', kernel='disk:5')
img.morphology(method='edge', kernel='diamond:1')
img.save(filename='0_wand_trim.png')
display(img)
关于python - 使用OpenCV进行垂直曲线检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57186182/