python - 使用OpenCV进行垂直曲线检测

标签 python image opencv image-processing detection

我想检测图像中间的垂直曲线。你知道怎么做吗?我想用线将左侧和右侧分开。我应该使用什么功能或过滤器?非常感谢您提出如何检测线路的想法。

图片链接如下:

enter image description here

顺便说一句:我在 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)


输入:

enter image description here

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


阈值:

enter image description here

连接组件:

enter image description here

平滑:

enter image description here

结果:

enter image description here

这是使用 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/

相关文章:

python - tensorflow:如何喂养 numpy.ndarray?

python - 如何使用 django channel

python - 如何使用python从特定关键字中提取有限行的数据

javascript - 随机图片加载不重复

opencv - 在 Xcode 中的 64 位 mac 上编译 opencv 2.4

python - Spark 中笛卡尔的替代品?

Android 特殊字符在 WebView 中转换为图像?

Android 保存和加载图像的最有效方式是什么?

android - 如何提高 OpenCV 实时检测器应用程序的 fps?

python - 2d 图像点和 3d 网格之间的交点