截取随意区域的图片
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@File : test9-1.py
@Author: Li,hui
@Date : 2020/7/3 4:45 下午
@Desc :
"""
import os, time
from PIL import Image
def test1(x1, y1, x2, y2, save_pic):
os.system("adb shell screencap -p > %s/original_pic.png" % (os.getcwd()))
time.sleep(5)
# 打开一张图
img = Image.open("original_pic.png")
box = (x1, y1, x2, y2)
img1 = img.crop(box)
pic1 = "input/img/rearview/service/du_refuel/%s.png" % save_pic
img1.save(pic1)
time.sleep(3)
if os.path.exists("original_pic.png"):
os.remove("original_pic.png")
print("'%s':截图执行成功" % save_pic)
else:
print("The file does not exist")
if __name__ == '__main__':
test1(274, 92, 742, 135, "选中222")