0

my first question here. (:

I'm trying to take a small screenshot in python and compare with a saved image, but I'm not getting it.

Here is my code:

im2 = Image.open("image2.bmp")
for y in range(200,300):
    box3=(40,y,92,y+9)
    im3 = ImageGrab.grab(box3)
    if(im3==im2):
        print("OK")
    #print(y)

and here is the main problem: image

There is one way to transform back the BmpImageFile to Image? I know if I compare two "Image" that will work fine.

Thanks!

1 Answers1

0

I found my solution here and I'll put the solution here. (from: How can I quantify difference between two images?)

from PIL import ImageGrab,Image,ImageChops

im2 = Image.open("image2.bmp")
for y in range(200,300):
    box3=(40,y,92,y+9)
    im3 = ImageGrab.grab(box3)
    diff = ImageChops.difference(im2, im3)
    im3.close()
    #print(diff.getbbox())
    if(diff.getbbox()==None):
        print("Ok")