I have a reqirement in my project. I need to capture the image in webcam and then compare every 4rth frame and see if there is a change in image and if there is a change i need to able to mark the area and send an alert to user or so... Any idea on How to compare the images...My manager told me to cut the image into 3*3 pixel and put it in a grid and then compare. any idea on this would really help me.

Recommended Answers

All 5 Replies

Hi Azam,

Thanks ,..But actually after comparing the images.. I should be able to select the area where there is a change. any help??

That's easy. All you have to do is to save the x,y position when firstPixel != secondPixel. Here's how its done:

The Method:

private bool ImageCompareArray(Bitmap firstImage, Bitmap secondImage, List<Point> diffPixels)
        {
            bool flag = true;
            string firstPixel;
            string secondPixel;

            if (firstImage.Width == secondImage.Width
               && firstImage.Height == secondImage.Height)
            {
                for (int i = 0; i < firstImage.Width; i++)
                {
                    for (int j = 0; j < firstImage.Height; j++)
                    {

                        firstPixel = firstImage.GetPixel(i, j).ToString();
                        secondPixel = secondImage.GetPixel(i, j).ToString();

                        if (firstPixel != secondPixel)
                        {
                            diffPixels.Add(new Point(i, j));
                            if (flag == true)
                                flag = false;
                        }
                    }
                }

                if (flag == false)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }

        }

Example use:

List<Point> [B]diffPixels[/B] = new List<Point>();

    if (!ImageCompareArray(new Bitmap("C:\\first.bmp"), new Bitmap("C:\\second.bmp"), [B]diffPixels[/B]))
     {
          foreach (Point p in [B]diffPixels[/B])
          {
             MessageBox.Show("Pixels are different at " + p.X.ToString() + ", " + p.Y.ToString());
            }
       }

Thanks

hi azam thanks for your inputs.
Actually i need to identify any object and then when there is a position change or if it is missing . I should put some rectangle on it. This is my requirement.Please through some light on this..

Do you also have any idea if all this can be done using EMGU CV( wrapper for Open CV).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.