Hi,
I was trying to put together some code to determine wither two photographs are different i.e. someone is standing in one and not the other. Write now this is what I have - it returns a percentage of colour difference and generally if it's above 50% there is something else in it.
This code is ridiculously slow to run and takes about a minute or so... I need it in seconds! It's even slow with the thumbnail sized images.
I'm not looking for anything hugely accurate - the big problem doing this is clearly that a pixel is going to be different depending on light levels.
I'd be really grateful for any suggestions, feedback or an existing solution that I can easily use.
I'm not a coder - so I'm trying to keep it simple - feel free to tell me what im doing wrong! It's good to share.
void compareImages ()
{
Debug.Print("Comparing Images");
int height = camera.CurrentPictureResolution.Height;
int width = camera.CurrentPictureResolution.Width;
int DiferentPixels = 0;
Bitmap container = new Bitmap(width, height);
for (int i = 0; i < width; i++) // increment by ten in width
{
for (int j = 0; j < height; j++) // increment in ten by height
{
Debug.Print("doing...");
Color currentPixel1 = picture1.GetPixel(i, j);
int r1 = ColorUtility.GetRValue(currentPixel1);
int g1 = ColorUtility.GetGValue(currentPixel1);
int b1 = ColorUtility.GetRValue(currentPixel1);
Color currentPixel2 = picture2.GetPixel(i, j);
int r2 = ColorUtility.GetRValue(currentPixel2);
int g2 = ColorUtility.GetGValue(currentPixel2);
int b2 = ColorUtility.GetRValue(currentPixel2);
if (r1 != r2 && g1 != g2 && b1 != b2)
{
DiferentPixels++;
container.SetPixel(i, j, GT.Color.Red);
}
else
container.SetPixel(i, j, picture1.GetPixel(i, j));
}
}
int TotalPixels = width * height;
float difference = (float)((float)DiferentPixels / (float)TotalPixels);
float percentage = difference * 100;
oledDisplay.SimpleGraphics.DisplayImage(container, 0, 0);
Debug.Print("Difference: " + difference + "Percentage Difference: " + percentage);
}