已在Stackoverflow.com和谷歌上搜索过。但除了下面显示的链接外,没有找到任何正确的方法。
compare two images and extract the difference using emgu cv library
请建议或提供有用的反馈,以便我可以启动该应用程序。
答案 0 :(得分:2)
请查看Emgu CV API文档,了解Image类的方法。
它包含方法AbsDiff来计算两个图像之间的绝对差异。它还提供Cmp来获取两个图像之间差异的比较掩码。
要获得描述差异的单个值,您可以使用Image.CountNonzero方法提供的每个通道的非零像素数。然后找到具有最大更改(非零)像素数的通道。要获得相对值(百分比),只需将其除以width * height
(图像中的总像素数)。
答案 1 :(得分:1)
使用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.
}
}
答案 2 :(得分:0)
我认为你在寻找:
image1 = image2 - image1;
由于运算符重载,可以直接在Emgu CV
中进行。
这里是位代码片段,可以帮助您使用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.
感谢
答案 3 :(得分:0)
如果要在比较两个图像后获得一个值,可以在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)之间的值,意味着更多匹配项