def main(): # 从设备获得屏幕截图 cfg = Config() cfg.screenshot_to_disk = True cfg.screenshot_to_disk_file_name = './temp/screenshot.png' print(cfg) if cfg.device_type == 'ios': d = IOSDevice(cfg=cfg) elif cfg.device_type == 'android': d = AndroidDevice(cfg=cfg) else: exit(0) d.screen_capture_handler()
def __init__(self, cfg=None, address='http://127.0.0.1:8100'): self.client = wda.Client(address) self.session = self.client.session() self.dpi = self.session.scale x, y = self.session.window_size() self.screen_x, self.screen_y = x * self.dpi, y * self.dpi self.cfg = cfg if cfg is not None else Config()
def main(): # 从设备获得屏幕截图 cfg = Config() # cfg.device_type = 'local' print(cfg) width = 1136 height = 640 if cfg.device_type == 'ios': d = IOSDevice(cfg=cfg) width = d.screen_x height = d.screen_y screen = d.screen_capture_handler(gray=False) elif cfg.device_type == 'android': d = AndroidDevice(cfg=cfg) width = d.screen_x height = d.screen_y screen = d.screen_capture_handler(gray=False) else: # 读取本地磁盘的截屏文件 screen = cv2.imread(cfg.screenshot_to_disk_file_name) # 灰度转换方法一: 读取RGB后转换 screen_gray = cv2.cvtColor(screen, cv2.COLOR_RGB2GRAY) # 灰度转换方法二: 直接读取 # screen_gray = cv2.imread(image_path, 0) feature_paths = [ ('./games/arknights/assets/scenes_feature/prts_disable_detection-3rd-anniversary.png', 0.7), ('./games/arknights/assets/scenes_feature/level_info_detection-3rd-anniversary.png', 0.7), ('./games/arknights/assets/scenes_feature/level_finish_detection.png', 0.7), ('./games/arknights/assets/scenes_feature/level_fighting_detection.png', 0.7), ('./games/arknights/assets/scenes_feature/level_team_detection.png', 0.7), ] for fp in feature_paths: feature = cv2.imread(fp[0], 0) feature_w, feature_h = feature.shape[::-1] res = cv2.matchTemplate(screen_gray, feature, cv2.TM_CCOEFF_NORMED) print(fp[0]) possible_targets = [] # 使用灰度图像中的坐标对原始RGB图像进行标记 loc = np.where(res >= fp[1]) for pt in zip(*loc[::-1]): x, y = pt[0] + feature_w / 2, pt[1] + feature_h / 2 if len(possible_targets) > 0: last = possible_targets[len(possible_targets) - 1] if x - last[0] > 20: possible_targets.append((x, y)) else: possible_targets.append((x, y)) cv2.rectangle(screen, pt, (pt[0] + feature_w, pt[1] + feature_h), (7, 249, 151), 2) print(possible_targets) # 红色方框框出不可点击区域 if cfg.game_name == 'azurelane': red_zones = EnemySearch.red_zones for i in range(len(red_zones)): zone = red_zones[i] cv2.rectangle(screen, zone[0], zone[1], (0, 0, 255), 3) # 显示图像 window_name = "detect-result" cv2.namedWindow(window_name, 0) cv2.resizeWindow(window_name, width, height) cv2.moveWindow(window_name, 100, 100) cv2.imshow(window_name, screen) cv2.waitKey(0) cv2.destroyAllWindows()
import requests from common.logutil import logger from common.runtime import Config url = "https://sc.ftqq.com/{0}.send?text={1}&desp={2}" cfg = Config() def program_exit_alert(cause): if cfg.server_chan_enable: secret = cfg.server_chan_secret params = { "title": "复读机复读结束通知", "desp": "游戏:{0}\n\n关卡:{1}\n\n结束原因:{2}\n\n" \ .format(cfg.game_name, cfg.battle_no, cause) } resp = requests.get(url.format(secret, params['title'], params['desp'])) json_string = bytes.decode(resp.content) logger.debug(json_string)
def __init__(self, cfg=None, address='127.0.0.1:7555'): self.adb = Adb(device=address) self.adb.test_device() self.__check_screenshot() self.screen_x, self.screen_y = self.adb.get_size() self.cfg = cfg if cfg is not None else Config()