[code]# -*- coding: utf-8 -*-"""手机屏幕截图的代码: screenshot.py"""import subprocessimport osimport sys,refrom PIL import Imageimport osimport time,randomimport cv2import aircv as acimport numpy as np# SCREENSHOT_WAY 是截图方法,经过 check_screenshot 后,会自动递减,不需手动修改SCREENSHOT_WAY = 1def run_cmd( cmd_str='', echo_print=1): """ 执行cmd命令,不显示执行过程中弹出的黑框 备注:subprocess.run()函数会将本来打印到cmd上的内容打印到python执行界面上,所以避免了出现cmd弹出框的问题 :param cmd_str: 执行的cmd命令 :return: """ from subprocess import run if echo_print == 1: print('\n执行cmd指令="{}"'.format(cmd_str)) run(cmd_str, shell=True)def run_cmd_Popen_fileno(cmd_string): """ 执行cmd命令,并得到执行后的返回值,python调试界面输出返回值 :param cmd_string: cmd命令,如:'adb devices' :return: """ import subprocess print('运行cmd指令:{}'.format(cmd_string)) return subprocess.Popen(cmd_string, shell=True, stdout=None, stderr=None).wait()def run_cmd_Popen_PIPE(cmd_string): """ 执行cmd命令,并得到执行后的返回值,python调试界面不输出返回值 :param cmd_string: cmd命令,如:'adb devices"' :return: """ import subprocess print('运行cmd指令:{}'.format(cmd_string)) return subprocess.Popen(cmd_string, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='gbk').communicate()[0]def pull_screenshot(xh,sjh,xx): """ 获取屏幕截图,目前有 0 1 2 3 四种方法,未来添加新的平台监测方法时, 可根据效率及适用性由高到低排序 """ global SCREENSHOT_WAY SCREENSHOT_WAY=xh if 1 |