January 21st, 2005, 07:42 PM
Compare two images...
How can I compare images. Using the code below I am comparing strings, I believe.
Is there another way ?
if "C:\image\directory\one\image.jpg" == "C:\image\directory\two\image.jpg":
print "They match"
print "They don't match"
January 21st, 2005, 09:17 PM
Maybe if you could open the image in notepad/wordpad and see the "code" thats in there, you could see if that code is the same as the other image. That might work.
file1 = 'C:\image\directory\one\image.jpg'
file2 = 'C:\image\directory\two\image.jpg'
if file1 == file2:
print "The files are identical."
print "The files are different."
January 21st, 2005, 09:49 PM
January 22nd, 2005, 04:52 AM
If you want to test that the two image files are identical then use the file comparison library function:
The 'shallow=False' forces the function to do a byte-by-byte comparison rather than just compare size and timestamp.
same = filecmp.cmp(file1, file2, shallow=False)
Dave - The Developers' Coach