PIL截取图片进行对比

from PIL import ImageGrab
from PIL import Image
import os
from os.path import *
# 获取对应的路径信息
def picture_path():
    path = dirname(dirname(abspath(__file__)))
    pict_path = os.path.join(path,"picture")
    return pict_path
# 进行封装
class Jt():
    def __init__(self):
        self.tp_path = picture_path()

        # 截图操作
    def scr_shoot(self,tp_name):
        image = ImageGrab.grab() # 使用ImageGrab.grab()进行截图操作
        image.save(self.tp_path+"//{}.png".format(tp_name)) # 保存到对应的路径下


     # 图形对比
    def gc(self,tp_name_one,tp_name_two):
        image = Image.open(self.tp_path+"//{}.png".format(tp_name_one))
        image_two = Image.open(self.tp_path+"//{}.png".format(tp_name_two))  # 打开对应位置的图片信息
        res_one_picture = image.histogram()
        res_picture = image_two.histogram()  # image.histogram()为list数据,当两张图片
        assert res_one_picture == res_picture   # assert进行对比
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值