def open(self, type, times): red_y = 700 red_x_20 = 200 red_x_100 = 550 red_x_500 = 900 album_x = 500 album_y = 1500 if type == '20': x = red_x_20 y = red_y elif type == '100': x = red_x_100 y = red_y elif type == '500': x = red_x_500 y = red_y elif type == 'album': x = album_x y = album_y else: return for i in range(times): Adb.tap_random(x - 100, y - 100, x + 100, y + 100) time.sleep(0.2) if i % 10 == 0: Adb.screen_shot(self.__png_name, self.__screenshot_path) for i in range(10): Adb.tap_random(red_x_500 - 100, red_y - 100, red_x_500 + 100, red_y + 100) time.sleep(0.2) Adb.screen_shot(self.__png_name, self.__screenshot_path)
def __ad_close_template(self, img, close_pos, close_template_name): threshold = 0.85 close_template = cv2.imread(close_template_name, 0) close = img[close_pos['y0']:close_pos['y1'], close_pos['x0']:close_pos['x1']] match_rate = cv2.matchTemplate(close, close_template, cv2.TM_CCOEFF_NORMED) # print(close_template_name) # print(match_rate) if (match_rate > threshold).any(): Adb.tap_random(close_pos['x0'] + 20, close_pos['y0'] + 20, close_pos['x1'] - 20, close_pos['y1'] - 20) time.sleep(2) Adb.tap_random(270, 585, 270 * 3, 585 * 3) return 1 return 0
def __ad_start(self): png_file = Adb.screen_shot(self.__png_name, self.__screenshot_path) img = cv2.imread(png_file, 0) threshold = 0.975 ad_pos = {'x0': 945, 'y0': 255, 'x1': 1045, 'y1': 345} ad_template = cv2.imread(self.__ad_template_path + '/ad_template.png', 0) ad = img[ad_pos['y0']:ad_pos['y1'], ad_pos['x0']:ad_pos['x1']] match_rate = cv2.matchTemplate(ad, ad_template, cv2.TM_CCOEFF_NORMED) # print('start:') # print(match_rate) if (match_rate > threshold).any(): Adb.tap_random(ad_pos['x0'] + 20, ad_pos['y0'] + 20, ad_pos['x1'] - 20, ad_pos['y1'] - 20) time.sleep(1) Adb.tap_random(590, 1450, 960, 1520)
def train_template(self, template=False) -> bool: # template = False if template: img1 = cv2.imread('./screenshot/jia_guo_meng.png')[1855:1920, 625:695] # 1 img2 = cv2.imread('./screenshot/jia_guo_meng.png')[1770:1850, 785:850] # 2 img3 = cv2.imread('./screenshot/jia_guo_meng.png')[1715:1750, 935:980] # 3 cv2.imwrite('./template/jiaguomeng/1.png', img1) cv2.imwrite('./template/jiaguomeng/2.png', img2) cv2.imwrite('./template/jiaguomeng/3.png', img3) return png_file: str = Adb.screen_shot(self.__png_name, self.__screenshot_path) img = cv2.imread(png_file) for house in self.__houses: center: tuple = self.__find_center(img, house) if center: Adb.swipe(center[0], center[1], self.__pos[house][0], self.__pos[house][1], 250) return True return False
def __ad_close(self): png_file = Adb.screen_shot(self.__png_name, self.__screenshot_path) img = cv2.imread(png_file, 0) is_close = 0 top_right_close_pos1 = {'x0': 955, 'y0': 115, 'x1': 1040, 'y1': 200} top_right_close_template1 = self.__ad_template_path + '/top_right_close_template1.png' is_close += self.__ad_close_template(img, top_right_close_pos1, top_right_close_template1) top_right_close_pos2 = {'x0': 940, 'y0': 115, 'x1': 1040, 'y1': 215} top_right_close_template2 = self.__ad_template_path + '/top_right_close_template2.png' is_close += self.__ad_close_template(img, top_right_close_pos2, top_right_close_template2) top_right_close_pos3 = {'x0': 950, 'y0': 125, 'x1': 1030, 'y1': 205} top_right_close_template3 = self.__ad_template_path + '/top_right_close_template3.png' is_close += self.__ad_close_template(img, top_right_close_pos3, top_right_close_template3) top_right_close_pos4 = {'x0': 945, 'y0': 120, 'x1': 1035, 'y1': 210} top_right_close_template4 = self.__ad_template_path + '/top_right_close_template4.png' is_close += self.__ad_close_template(img, top_right_close_pos4, top_right_close_template4) top_right_close_pos5 = {'x0': 945, 'y0': 120, 'x1': 1035, 'y1': 210} top_right_close_template5 = self.__ad_template_path + '/top_right_close_template5.png' is_close += self.__ad_close_template(img, top_right_close_pos5, top_right_close_template5) top_left_close_pos1 = {'x0': 60, 'y0': 120, 'x1': 150, 'y1': 210} top_left_close_template1 = self.__ad_template_path + '/top_left_close_template1.png' is_close += self.__ad_close_template(img, top_left_close_pos1, top_left_close_template1) return is_close
def update(self, milli): Adb.swipe(900, 2150, 900, 2150, milli) Adb.screen_shot(self.__png_name, self.__screenshot_path)
def __auto_tap(self): for k in self.__pos: Adb.tap_random(self.__pos[k][0] - 25, self.__pos[k][1] - 25, self.__pos[k][0] + 25, self.__pos[k][1] + 25) time.sleep(0.25)
def __force_close(self): Adb.tap(1000, 160) time.sleep(2) Adb.tap_random(270, 585, 270 * 3, 585 * 3)