Вопрос

I am doing a motion detection app as A c# winform app.

I use openCV and the emgu wrapper to discern motion (that I want to trap).

A lot of the time there are no motion changes but I still have to check this within my code.

I gave md5 a go just to see if I could use this to detect quickly if there were any differences between 2 images. I have found in 99% of the time that the md5s of 2 images do not match and thus tells me there are differences between the 2 images. I am assuming for motion detection that md5 would not be too 'sensitive' for such a task?

Can Md5 be set to have % difference threshold or/and is there another way to do this?

thanks

code so far:

   private  string getMd5Hash(byte[] buffer)
    {
        MD5 md5Hasher = MD5.Create();
        byte[] data = md5Hasher.ComputeHash(buffer);

        StringBuilder sBuilder = new StringBuilder();
        for (int i = 0; i < data.Length; i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }
        return sBuilder.ToString();
    }

   public  string GetMD5(byte[] buffer)
   {
      return getMd5Hash(buffer);
   }

//calling code...

        string img1= t.GetMD5(data);
        string img2= t.GetMD5(data);

        if (img1!= img2)
        {
          //differences
        }
Это было полезно?

Решение

MD5 is a cryptographic hash function, as such it intentionally produces a vastly different hash if even a single bit changes in its input. Therefore, just because two inputs are "close" (i.e. have few differences), the MD5 hashes will not be, that's inherent in the algorithm, and can't be "tuned" in the way you require.

There are many methods to detect similar images. One possibility is given here: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

The basic method given is to convert the images being compared to grayscale, resize them so that they are only a few pixels wide/tall, and then convert each pixel to black/white (1 bit/pixel) by comparing it to the average value of all pixels. Then you can compute pixel differences between the two images - the greater the number of different pixels, the greater the likely difference in the original images.

This method can be tuned by changing how much you reduce the original image - the more you reduce it, the less sensitive it'll be to differences between the images.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top