def screen_pressed(self, instance): try: os.makedirs('data', exist_ok=True) filename = os.path.join('data', '%d.png' % time.time()) screen_recorder.get_screenshot (5).save (filename) if self.use_overlay: game_overlay_sdk.injector.send_message('ScreenShot saved to %s' % filename) logging.info('ScreenShot saved to %s' % filename) self.screenshot.source = filename self.screenshot.reload() except Exception as e: logging.error(str(e))
def main(): screen_recorder.enable_dev_log() pid = int(sys.argv[1]) screen_recorder.init_resources(pid) screen_recorder.get_screenshot(5).save('test_before.png') screen_recorder.start_video_recording('video1.mp4', 30, 8000000, True) time.sleep(5) screen_recorder.get_screenshot(5).save('test_during_video.png') time.sleep(5) screen_recorder.stop_video_recording() screen_recorder.start_video_recording('video2.mp4', 30, 8000000, True) time.sleep(5) screen_recorder.stop_video_recording() screen_recorder.free_resources()
def startFullscreen(self): w, h, x, y = self.win.computeBox() try: img = rec.get_screenshot(1) self.img = img.crop((x, y, w + x, h + y)) self.compare() except Exception as e: rec.free_resources() self.stop() return
def main(): if ctypes.windll.shell32.IsUserAnAdmin() == 0: log('Please run as administrator') exit(0) global waiting_for, current_match, pause_between_screenshots ensure_file_structure() log('-- Searching for Overwatch.exe') overwatch_pid = get_pid() log('-- Overwatch PID is', overwatch_pid) while get_pid_state(overwatch_pid) == 2: log('-- Overwatch is minimized') time.sleep(5) log('-- Overwatch is open, initializing') time.sleep(4) # Pause before initializing # screen_recorder.enable_dev_log() screen_recorder.disable_log() screen_recorder.init_resources(overwatch_pid) log('-- Initialized resources') load_state() log( '-- Loaded state:', waiting_for, current_match['scoreboard_file'] if current_match is not None else None) prev_pid_state = 1 pid_state = 1 while True: time.sleep(pause_between_screenshots) cycle_time = time.strftime("%Y-%m-%d-%H-%M-%S") prev_pid_state = pid_state pid_state = get_pid_state(overwatch_pid) if pid_state == 2: log('-- Overwatch is minimized') continue if pid_state is None: log('Overwatch has closed') exit(0) if prev_pid_state == 2: time.sleep(5) pil_image = None try: pil_image = screen_recorder.get_screenshot(1) except screen_recorder.RecorderError as err: log(f"Error taking screenshot", err) restart_program() if pil_image: img = pil_to_cv2_image(pil_image) if waiting_for == 'scoreboard': log('-- Waiting for a SCOREBOARD') match, value = is_matched(img, scoreboard_template) if match: log('Found scoreboard', match, value) # This screenshot shows scoreboard try: filename = f'./scoreboards/scoreboard_{cycle_time}.png' players = recognize_scoreboard(img) current_match = { 'scoreboard_file': filename, 'players': players } waiting_for = 'result' cv2.imwrite(filename, img, [cv2.IMWRITE_PNG_COMPRESSION, 9]) save_state() except: filename = f'./scoreboards_errors/scoreboard_{cycle_time}.png' cv2.imwrite(filename, img, [cv2.IMWRITE_PNG_COMPRESSION, 9]) traceback.print_exc(file=sys.stdout) log(f"Error recognizing {filename}") if waiting_for == 'result': log('-- Waiting for a RESULT') result, value = match_result(img) if result is not None: log(f"Found result: {result}, confidence: {value}") filename = current_match['scoreboard_file'].replace( 'scoreboard_', 'scoreboard_result_') cv2.imwrite(filename, img, [cv2.IMWRITE_PNG_COMPRESSION, 9]) with open("results.json", "r+") as file: results_array = json.load(file) results_array.append({ 'result': result, 'result_file': filename, 'scoreboard_file': current_match['scoreboard_file'], 'players': current_match['players'] }) file.seek(0) json.dump(results_array, file, indent=1) with open("results_short.json", "r+") as file: results_array = json.load(file) results_array.append({ 'result': result, 'result_file': filename, 'players': list( map(get_player_level, current_match['players'])) }) file.seek(0) json.dump(results_array, file, indent=1) waiting_for = 'scoreboard' current_match = None save_state()
def run(self): i = 0 while not self.should_stop: screen_recorder.get_screenshot(5).save('test' + str(i) + '.png') time.sleep(1) i = i + 1