【问题标题】:Identify a shape inside another shape using AForge.Net使用 AForge.Net 识别另一个形状内的形状
【发布时间】:2012-10-24 04:07:27
【问题描述】:

作为项目的一部分,我正在使用 AForge.Net 库来做一些基本的图像处理工作。我发现识别图像中的单个几何形状(如正方形、圆形等)是微不足道的。但是,当我有一个像 ,程序只能识别外圈。我希望它被识别为一个圆圈和一条线。

类似的另一个例子是, ,程序只识别一个正方形,但我需要它来识别它是一个正方形和一个圆形。

我猜这个库本身已经过时并且不再受支持,但我非常感谢一些帮助!我发现这是一个非常容易使用的库,但如果我的要求不能满足它,我也对其他库开放。 (在 Java、C# 或 Python 中)。谢谢!

【问题讨论】:

    标签: c# image-processing


    【解决方案1】:

    使用Python 是一项简单的任务
    您需要安装 numpyscipy.ndimage 之类的库,并且仅使用 scipy.ndimage 您可以提取黑色背景上的任何形状。
    因此,如果您的图像是白色背景,您需要先将其反转,这很容易。

    import scipy.ndimage  
    from scipy.misc import imread           # so I can read the image as a numpy array
    
    img=imread('image.png')        # I assume your image is a grayscale image with a black bg.  
    labeled,y=scipy.ndimage.label(img)   # this will label all connected areas(shapes).  
                                             #y returns how many shapes??  
    
    shapes=scipy.ndimage.find_objects(labeled)         
    # shapes returns indexing slices for ever shape  
    # So if you have 2 shapes in your image,then y=2.
    # to extract the 1st shape you do like this.  
    first_shape=img[shapes[0]]          # that's is a numpy feature if you are familiar with numpy .
    second_shape=img[shapes[1]]  
    

    提取您的个人形状后,您实际上可以做一些数学工作来确定它是什么?(例如圆形度比>>您可以谷歌它,这对您的情况很有帮助)

    【讨论】:

    • 谢谢。这是我目前正在探索的选项之一!再次感谢您为我指明正确的方向。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    • 2017-12-10
    • 1970-01-01
    相关资源
    最近更新 更多