【问题标题】:How can I compare two still images using emgu cv in c#如何在 c# 中使用 emgu cv 比较两个静止图像
【发布时间】:2014-04-02 08:39:01
【问题描述】:

在 Stackoverflow.com 和谷歌上搜索过。但是除了下面显示的链接之外,没有找到任何合适的方法。

compare two images and extract the difference using emgu cv library

请建议或提供有用的反馈,以便我可以开始使用该应用程序。

【问题讨论】:

  • 你在code project查看过这个教程
  • @Nimesh 我需要将草图图像与普通彩色图像进行比较。所以这无济于事
  • 你能发一张示例图片吗?
  • 我的素描图像:tiikoni.com/tis/view/?id=8961a3a 我的彩色图像:tiikoni.com/tis/view/?id=067deae
  • 这里你必须使用Extended Uniform Circular Local Binary Patterns (EUCLBP)来比较草图图像和数字图像。

标签: c# winforms emgucv


【解决方案1】:

请查看 Emgu CV API 文档以了解 Image 类的方法。

它包含方法AbsDiff 来计算两个图像之间的绝对差异。它还提供Cmp 来获取两个图像之间差异的比较掩码。

要获得描述差异的单个值,您可以使用Image.CountNonzero 方法提供的每个通道的非零像素数。然后找到具有最大更改(非零)像素数的通道。要获得相对值(百分比),只需将其除以 width * height(图像中的像素总数)即可。

【讨论】:

  • AbsDiff 给了我图像格式的差异,但我需要百分比或任何十进制值的差异。有可能吗???
  • 嗨,我添加了一个简单的方法来获取描述两个图像差异的单个值。但这很粗糙,而且我很早以前就使用过这个库。希望对您有所帮助
  • @andyp Then find the channel with the maximum number of changed (non-zero) pixels. 是什么意思我该怎么做?我还想计算两个图像之间差异的百分比或图像的相似性百分比。你能帮忙吗stackoverflow.com/questions/36193475/…
  • @Amogh 你找到解决方案了吗?
【解决方案2】:

使用 EmguCV 的 AbsDiff 方法。

       using (Image<Gray, byte> sourceImage = new Image<Gray, byte>(_orgImage))
        {
        using (Image<Gray, byte> templateImage = new Image<Gray, byte>(_refImage))
        {
            Image<Gray, byte> resultImage = new Image<Gray, byte>(_bufferParams.MaskDetails.width, _bufferParams.MaskDetails.height);
            CvInvoke.AbsDiff(sourceImage, templateImage, resultImage);
            //resultImage.Save(@"some path" + "imagename.jpeg");
            int diff = CvInvoke.CountNonZero(resultImage);
            //if diff = 0 exact match, otherwise there are some difference.
         }     
        }

【讨论】:

    【解决方案3】:

    我想你在找什么:

    image1 = image2 - image1;
    

    由于运算符重载,这可以直接在Emgu CV 中实现。 这是位代码 sn-p 可以帮助您使用 Emgu CV lib 实现目标。

    Image<Gray, Byte> img1 = new Image<Gray, Byte>("C:\\image1.png"); 
    Image<Gray, Byte> img2 = new Image<Gray, Byte>("C:\\image2.png"); 
    Image<Gray, Byte> img3 = img2 - img1; //Here the difference is applied.
    

    谢谢

    【讨论】:

    • 这对我来说会抛出一个错误,例如“操作既不是'array op array'(其中数组具有相同的大小和相同的通道数),也不是'array op scalar',也不是'scalar op array"...你能帮忙吗?
    【解决方案4】:

    如果你想在比较两张图片后得到一个值,你可以在 EmguCV 中使用 MatchTemplate API。

    Image<Gray, float> resultImage = sourceImage.MatchTemplate(templateImage, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed);
                        double[] minValues, maxValues;
                        Point[] minLocations, maxLocations;
    resultImage.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
    

    maxValues[0] 会给你一个介于 0-1 之间的值,接近 1,意味着更多匹配

    【讨论】:

    • 这不是量化或检测图像差异及其存在位置的可靠方法。
    • Nouman,请在此线程中查看我的另一个答案。使用 EmguCV 的 AbsDiff 方法。
    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 2015-03-08
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    相关资源
    最近更新 更多