[英]Compare PIL Image and BmpImageFile in Python
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.我正在尝试在 python 中截取一个小屏幕截图并与保存的图像进行比较,但我没有得到它。
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 ?有一种方法可以将BmpImageFile转换回Image吗? I know if I compare two " Image " that will work fine.
我知道如果我比较两个“图像”就可以了。
Thanks!谢谢!
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.