#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    37
    Rep Power
    11

    Compare two images...


    How can I compare images. Using the code below I am comparing strings, I believe.

    Code:
    if "C:\image\directory\one\image.jpg" == "C:\image\directory\two\image.jpg":
    print "They match"
    else:
    print "They don't match"
    Is there another way ?
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Code:
    file1 = 'C:\image\directory\one\image.jpg'
    file2 = 'C:\image\directory\two\image.jpg'
    if file1 == file2:
        print "The files are identical."
    else:
        print "The files are different."
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    37
    Rep Power
    11
    Works. Thanks!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    If you want to test that the two image files are identical then use the file comparison library function:

    Code:
    import filecmp
    same = filecmp.cmp(file1, file2, shallow=False)
    The 'shallow=False' forces the function to do a byte-by-byte comparison rather than just compare size and timestamp.

    Dave - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo