用于爬虫,或者ui自动化的相关工具
def get_target_pic(xmin:int ,ymin:int, xmax:int ,ymax:int,img_path:str,new_img_path:str,driver:object):
'''
当前函数用于使用selenium截图页面,进行截图使用
:param xmin: 裁剪位置
:param ymin: 裁剪位置
:param xmax: 裁剪位置
:param ymax: 裁剪位置
:param img_path: 存储截图的路径
:param new_img_path: 裁剪的图片的路径
:return: 返回截取的图片所在的路径
'''
from PIL import Image
driver.get_screenshot_as_file(img_path)
im = Image.open(img_path) # 用PIL打开一个图片
box = (xmin, ymin, xmax, ymax) # box代表需要剪切图片的位置格式为:xmin ymin xmax ymax
ng = im.crop(box) # 对im进行裁剪 保存为ng(这里im保持不变)
ng.save(new_img_path)
return new_img_path
def pic_img(pic_path:str):
'''
获取图片上的中文
:param pic_path: 图片路径
:return: 返回图片上的文字
'''
from PIL import Image
import pytesseract
# 读取图片
image_obj = Image.open(pic_path)
text = pytesseract.image_to_string(image_obj, lang='chi_sim')
return text