【问题标题】:Measure difference of two images using emgucv使用 emgucv 测量两个图像的差异
【发布时间】:2013-06-08 16:01:53
【问题描述】:

我需要比较两张图片,并将它们的差异确定为百分比。 emgucv 上的“Absdiff”功能对此无济于事。我已经在 emgucv wiki 上完成了比较示例。我真正想要的是如何获得两个数字格式的图像差异?

//emgucv wiki compare example

//acquire the frame
Frame = capture.RetrieveBgrFrame(); //aquire a frame
 Difference = Previous_Frame.AbsDiff(Frame);
//what i want is
double differenceValue=Previous_Frame."SOMETHING";

如果您需要更多详细信息,请询问。 提前致谢。

【问题讨论】:

  • 您考虑过使用 MatchTemplate 功能吗?使用一张图片作为模板,另一张作为要匹配的图片。这会产生一个数值(浮点数),它对应于两个图像的相关程度。只是一个想法......

标签: c# image-processing compare emgucv


【解决方案1】:

基于 EmguCV MatchTemplate 的比较

Bitmap inputMap = //bitmap  source image
Image<Gray, Byte> sourceImage = new Image<Gray, Byte>(inputMap);

Bitmap tempBitmap = //Bitmap template image
Image<Gray, Byte> templateImage = new Image<Gray, Byte>(tempBitmap);

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);

double percentage = maxValues[0] * 100; //this will be percentage of difference of two images

两个图像需要具有相同的宽度和高度,否则 MatchTemplate 会抛出异常。如果我们想要完全匹配。 要么 模板图像应小于源图像以获得模板图像在源图像上出现的次数

【讨论】:

  • 请注意,两张图片需要具有相同的宽度和高度,否则MatchTemplate会抛出异常。
【解决方案2】:

基于 EmguCV AbsDiff 的比较

Bitmap inputMap = //bitmap  source image
Image<Gray, Byte> sourceImage = new Image<Gray, Byte>(inputMap);

Bitmap tempBitmap = //Bitmap template image
Image<Gray, Byte> templateImage = new Image<Gray, Byte>(tempBitmap);

Image<Gray, byte> resultImage = new Image<Gray, byte>(templateImage.Width, 
templateImage.Height);

CvInvoke.AbsDiff(sourceImage, templateImage, resultImage);

double diff = CvInvoke.CountNonZero(resultImage);

diff = (diff / (templateImage.Width * templateImage.Height)) * 100; // this will give you the difference in percentage

根据我的经验,与基于 MatchTemplate 的比较相比,这是最好的方法。匹配模板未能捕获两个图像中非常小的变化。 但是 AbsDiff 也能够捕捉到非常小的差异

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    相关资源
    最近更新 更多