I've red a few posts regarding image comparison, and I tried to save image captured from screen then store it in file system .
I used conversion methods to convert captured image into byte[]
for later use .
Then when I want to compare it to second screen capture, I load (file saved into byte[]
) and compare it against new capture that converted into byte[]
in the same way.
Now when having both 1st capture and 2nd capture, in memory, there was few ways to do the comparison, I wanted firstly to share this post with others searching for the same answer and for me to know :
Which is faster, and how do I control the percentage of the similarity?
If the option to have percentage (of equality) is opposing the fastest way to compute... I can disregard it, although I could use it in other projects when performance issue is not there, and according to its needs
These are the codes I know available to do the task
I wanted to check with you for ideas which is faster and if there's a better way at all with and without equality percentage. Thank you.
static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
IStructuralEquatable eqa1 = a1;
return eqa1.Equals(a2, StructuralComparisons.StructuralEqualityComparer);
}
vs
public enum CompareResult
{
ciCompareOk,
ciPixelMismatch,
ciSizeMismatch
};
CompareResult cr = CompareResult.ciCompareOk;
byte[] hash1 = shaM.ComputeHash(btImage1);
byte[] hash2 = shaM.ComputeHash(btImage2);
//Compare the hash values
for (int i = 0; i < hash1.Length && i < hash2.Length
&& cr == CompareResult.ciCompareOk; i++)
{
if (hash1[i] != hash2[i])
cr = CompareResult.ciPixelMismatch;
}
the later is using System.Security.Cryptography