使用EmguCV测量两幅图像的差异

3

我需要比较两张图片并以百分比的形式识别它们之间的差异。Emgucv上的“Absdiff”函数无法帮助我实现这一目标。我已经在Emgucv维基上完成了比较示例。我想知道如何以数字格式获取两张图片的差异?

//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函数吗? 将一个图像作为模板,另一个作为要匹配的图像。这将产生一个对应于两个图像相关程度的单个数值(浮点数)。只是一个想法... - Bryan Greenway
2个回答

0

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的比较相比,这是最佳方法。Match template无法捕捉两幅图像中非常微小的差异。而AbsDiff将能够捕捉到非常小的差异。

0

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将抛出异常。如果我们想要完全匹配的话。 或者 模板图像应该比源图像小,以获得模板图像在源图像上的多次出现。

2
请注意,这两个图像需要具有相同的宽度和高度,否则MatchTemplate将抛出异常。 - vaiperboy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接