【问题标题】:Why doesn't AForge.Net BlobCounter.GetObjectsInformation() detect objects?为什么 AForge.Net BlobCounter.GetObjectsInformation() 不检测对象?
【发布时间】:2016-03-14 06:18:30
【问题描述】:

我正在尝试使用 AForge.Net 来检测图像中的矩形。在测试图像(附在下面)中,我有以下代码。

        BlobCounter blobCounter = new BlobCounter();

        blobCounter.FilterBlobs = true;

        blobCounter.MinHeight = 5;
        blobCounter.MinWidth = 5;
        blobCounter.MaxHeight = 5000;
        blobCounter.MaxWidth = 5000;


        blobCounter.ProcessImage(currentImage);

        Blob[] blobs = blobCounter.GetObjectsInformation();

        // check for rectangles
        SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

但是,GetObjectsInformation() 只返回一个Blob,即全图。为什么它不能检测到内部矩形?我按照示例进行操作,但不知道哪里错了。任何帮助表示赞赏。

图片

编辑:好的。我发现如果我将图像存储为 PNG 格式,那么它可以检测到矩形。但是如果我将图像存储为 JPG 格式,那么它会失败。我不确定这是什么原因。我猜是因为 Jpeg 格式的信息丢失了。我在处理之前将图像加载到Bitmap

【问题讨论】:

  • 我猜你的 JPG 到 Bitmap 的转换有问题,Jpg 压缩在这里应该不是问题。为什么您的最大 blob 尺寸大于图像尺寸?
  • @Piglet 好吧,我设置最大 blob 尺寸只是为了测试它(我确实想在实际应用中使用它,但在这个例子中,我只是想确保它无关紧要) .我使用image = new Bitmap(input); 加载图像,其中图像是位图,输入是文件流。我还将加载的图像显示到 WPF Image 控件(进行必要的转换),我看不到任何视觉差异。
  • 如果您的最大 blob 大小小于图像尺寸,那么您应该无法将整个图像作为 blob 找到。
  • @Piglet 是的,但它会返回零对象被检测到。

标签: .net computer-vision aforge


【解决方案1】:

在搜索 blob 之前,您必须对图像进行预处理,因为 blob 计数器会在阈值图片(像素是纯白色或纯黑色)中搜索具有黑色背景的白色对象,并且您会得到一个 blob,因为白色背景是算作一个blob(全图)所以首先你必须做一些步骤

  1. 灰度图像(彩色到灰度)
  2. 阈值图像(灰度到白色和黑色)
  3. 反转图像(将矩形边框转换为白色)
  4. 搜索 blob

    public Bitmap PreProcess(Bitmap bmp)
    {
        //Those are AForge filters "using Aforge.Imaging.Filters;"
        Grayscale gfilter = new Grayscale(0.2125, 0.7154, 0.0721);
        Invert ifilter = new Invert();
        BradleyLocalThresholding thfilter = new BradleyLocalThresholding();
        bmp = gfilter.Apply(bmp);
        thfilter.ApplyInPlace(bmp);
        ifilter.ApplyInPlace(bmp);
        return bmp;
    }
    

调用此方法为您的图像准备 blob 搜索

blobCounter.ProcessImage(PreProcess(currentImage));

【讨论】:

    猜你喜欢
    • 2020-09-06
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    • 2011-10-26
    • 2020-12-12
    • 2020-11-01
    • 2018-06-15
    相关资源
    最近更新 更多