Reputation: 12672
I am using it to tell whether now screenshot is different from last screenshot. Now I use
with open('last_screenshot.bmp','rb+') as f:
org = f.read()
with open('now_screenshot.bmp','rb+') as f:
new = f.read()
if(org==new):
print("The pictures are same")
Is there a faster way to do this?
Upvotes: 1
Views: 399
Reputation: 942
You won't get nowhere comparing pixels. Your options:
Upvotes: 1
Reputation: 36239
You can use filecmp.cmp(..., shallow=False)
which ships with the standard library. This won't read the whole files into memory but instead read them in chunks and short-circuit when a differing chunk is encountered. Example usage:
import filecmp
if filecmp('last_screenshot.bmp', 'now_screenshot.bmp', shallow=False):
print('Files compare equal')
Upvotes: 0