I'm using Magick.NET with C# and using Selenium to take browser screenshots and then compare them to reference images (also taken by Selenium) and return the percent match between the two. If they are not close, it's fine. If they are exact duplicates (I make file1 and file2 point at the same file) then it shows 100%. When the images are not exactly duplicate, it often returns a match percentage that is...very large:
"PASS: Images are duplicate: 27,529,786,086.48 % - (275297860.864805)"
The second value is the same, just not converted to percent. This is for 2 .png screenshots of the same screen taken in succession and which thus have a very high similarity but are not binary equal. Is this a known issue? Also, if I change the ErrorMetric from Undefined to Absolute, I still get a hellaciously large value:
PASS: Images are duplicate: 78,402,600.00 % - (784026)
Here's my code, I've carved it down to the important bits, so I might be plus or minus a curly brace, and WriteToFile is our in-house logging:
void compareScreenshotImages(string file1, string file2, double accuracy)
{
TakeScreenshot(driver, file2);
"PASS: Images are duplicate: 27,529,786,086.48 % - (275297860.864805)"
The second value is the same, just not converted to percent. This is for 2 .png screenshots of the same screen taken in succession and which thus have a very high similarity but are not binary equal. Is this a known issue? Also, if I change the ErrorMetric from Undefined to Absolute, I still get a hellaciously large value:
PASS: Images are duplicate: 78,402,600.00 % - (784026)
Here's my code, I've carved it down to the important bits, so I might be plus or minus a curly brace, and WriteToFile is our in-house logging:
void compareScreenshotImages(string file1, string file2, double accuracy)
{
TakeScreenshot(driver, file2);
using (MagickImage image1 = new MagickImage(file1))
{
MagickImage compare = new MagickImage();
MagickImage image2 = new MagickImage(file2);
Double result = image1.Compare(image2, ErrorMetric.Undefined, compare);
compare.Write(compareresult);
if (result > accuracy) {
WriteToFile(String.Format(" PASS: Images are duplicate: {0:P2} - ({0})", result));
}
else {
WriteToFile(String.Format("ERROR: Result similarity: {0:P2} - ({0})", result));
}
}
}