Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to compare 2 JPG files in code?
Message
De
29/06/2010 21:18:44
 
 
À
29/06/2010 11:03:52
Mike Sue-Ping
Cambridge, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Divers
Thread ID:
01470953
Message ID:
01471037
Vues:
43
Hi Mike.

The problem here is that JPEG is a lossy format, so when you load the picture it translates into a 24 bit image and then when you save it, even if you use the exact same compression setting, the compression routine will wind up with a very subtly different picture. You don't see it with your eyes, but the two pictures don't look the same. If you tried loading and saving an image over and over eventually the errors would start to become visible.

There are two way around this, neither of which you are going to like. :-)
1) Use a lossless image format. That way you'll be saving the exact same thing each time.
2) Load the two images, subtract one form the other and then scan through the result looking for the magnitude of error across the image and if that is below a certain level then assume that they are the same image. You could probably use the GDIPlusX classes to help.

Comparing the two images is really tricky because there will be small differences across the entire image. If you have a decent image editor it will let you subtract the two images from each other and you can see with your eye what's happening. You will probably want to do something like a histogram equalisation to make the differences more visible.

Ian Simcock.


>Does anyone know if and how to compare two JPG photos using code?
>
>I tried filetostr() and while it seemed to work I found that it fails for the following set of commands:
>
>r = filetostr(path to photo 1)
>copy photo 1 to photo 2
>open photo 2 in a graphic editor (paint will do). Don't make any changes and save it.
>s = filetostr(path to photo 2)
>wait window r==s returns false!!!
>
>Simply changing re-saving the second photo was enough to make it different.
>
>As always, any assistance is greatly appreciated.
>
>TIA,
>Mike
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform