def _test(): tesseract = construct_tesseract() # debug_images = ( # # 1465, # Yellow # # 1463, # Blue # # 1459, # Red # # 1453, # White # 1516, # ) # # for path in ls_debug(explicit_options=debug_images): # for path in ls(DATA_DIR + "module_classifier/labelled/button", 10): # path = path.replace("-full-", "-module-").replace("labelled/button", "unlabelled") # print path # im = cv2.imread(path) # print get_button_color_label_and_location(im, tesseract) # # print get_strip_color(im)-= # show(im) # screenshots = ( # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.04.00.png", (2, 0)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.50.png", (2, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.41.png", (1, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.31.png", (0, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.20.png", (0, 0)), # ) # for path, module_position in screenshots: for path in ls_debug(1634, 1634): module_position = (0, 1) im = cv2.imread(path) screenshot_helper = ScreenshotHelper( inflate_classifier(MODULE_CLASSIFIER_DIR)) print get_clock_time_from_full_screenshot(im, module_position, screenshot_helper)
def __init__(self): super(WhosOnFirstSolver, self).__init__() self._button_classifier = inflate_classifier(WHOS_ON_FIRST_BUTTON_CLASSIFIER_DIR) self._tesseract = _get_tesseract() self._debug_image = 0
def _test(): tesseract = construct_tesseract() # debug_images = ( # # 1465, # Yellow # # 1463, # Blue # # 1459, # Red # # 1453, # White # 1516, # ) # # for path in ls_debug(explicit_options=debug_images): # for path in ls(DATA_DIR + "module_classifier/labelled/button", 10): # path = path.replace("-full-", "-module-").replace("labelled/button", "unlabelled") # print path # im = cv2.imread(path) # print get_button_color_label_and_location(im, tesseract) # # print get_strip_color(im)-= # show(im) # screenshots = ( # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.04.00.png", (2, 0)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.50.png", (2, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.41.png", (1, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.31.png", (0, 1)), # ("/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-14 23.03.20.png", (0, 0)), # ) # for path, module_position in screenshots: for path in ls_debug(1634, 1634): module_position = (0, 1) im = cv2.imread(path) screenshot_helper = ScreenshotHelper(inflate_classifier(MODULE_CLASSIFIER_DIR)) print get_clock_time_from_full_screenshot(im, module_position, screenshot_helper)
def test(): im = cv2.imread( "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0003.png" ) symbol_classifier = inflate_classifier(SYMBOLS_CLASSIFIER_DIR) symbols, positions = get_symbols_and_positions(im, symbol_classifier) print symbols order = get_symbol_order(symbols)
def test(): # to_test = (275, 280) # to_test = (1243, 1248) to_test = (1331, 1336) letter_classifier = inflate_classifier(PASSWORD_LETTER_CLASSIFIER_DIR) for f in ls_debug(*to_test): im = cv2.imread(f) print get_letters(im, letter_classifier) show(im)
def _extract_pieces(): # _, _, labelled_src_dir, _, _ = get_classifier_directories(MODULE_CLASSIFIER_DIR) # src_dir = os.path.join(labelled_src_dir, "memory") # _, buttons_dir, _, _, _ = get_classifier_directories(BUTTONS_CLASSIFIER_DIR) # _, screen_dir, _, _, _ = get_classifier_directories(SCREEN_CLASSIFIER_DIR) # button_template = os.path.join(buttons_dir, "{:04}.png") # screen_template = os.path.join(screen_dir, "{:04}.png") # # next_button = 0 # next_screen = 0 files = ( # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0121.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0122.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0123.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0135.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0973.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0974.png", "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0975.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0976.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0977.png", # "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0978.png", ) button_classifier = inflate_classifier(BUTTONS_CLASSIFIER_DIR) screen_classifier = inflate_classifier(SCREEN_CLASSIFIER_DIR) for i, f in enumerate(files): # if i >= 4: # break # if i != 3: # continue im = cv2.imread(f) buttons = _get_button_images(im) print _get_button_locations(im) screen = _get_screen_image(im) print "SCREEN:", screen_classifier(screen) for b in buttons: print "BUTTON:", button_classifier(b) show(im)
def play_game(): time.sleep(2) classifier = inflate_classifier(MODULE_CLASSIFIER_DIR) solvers = create_solvers() screenshot_helper = ScreenshotHelper(classifier) while True: start_game() open_bomb() screenshot_helper.initialize_while_open() sides_info = get_sides_info_while_open(screenshot_helper) solve_modules_on_this_side(solvers, sides_info, screenshot_helper) flip_side() # Ideally we could remove this close/open cycle close_once() open_bomb() solve_modules_on_this_side(solvers, sides_info, screenshot_helper) close_once() quit_game()
def test(): vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = \ get_classifier_directories(MODULE_CLASSIFIER_DIR) for path in ls(os.path.join(labelled_dir, "password")): im = cv2.imread(path) letter_classifier = inflate_classifier(PASSWORD_LETTER_CLASSIFIER_DIR) top_buttons, bottom_buttons = find_column_buttons(im) submit_button = find_submit_button(im) print get_letters(im, letter_classifier) for i, b in enumerate(top_buttons): cv2.circle(im, b, 5, (0, 0, 255)) cv2.putText(im, str(i), b, cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 0)) for i, b in enumerate(bottom_buttons): cv2.circle(im, b, 5, (0, 255, 0)) cv2.putText(im, str(i), b, cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 0)) cv2.circle(im, submit_button, 5, (255, 0, 0)) show(im)
def test(): tesseract = _get_tesseract() classifier = inflate_classifier(WHOS_ON_FIRST_BUTTON_CLASSIFIER_DIR) vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = \ get_classifier_directories(MODULE_CLASSIFIER_DIR) i = 0 # for path in ["/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/whos_on_first/in_game_6.png"]: # for path in ls(os.path.join(labelled_dir, "whos_on_first")): for path in ls_debug(1486, 1486): i += 1 # if i < 50: # continue # if i >= 50: # break # name = "-module-".join(os.path.basename(path).split("-full-")) # path = os.path.join(unlabelled_dir, name) im = cv2.imread(path) # show(im) screen_text = get_screen_content(im, tesseract, 9999)
def _get_text_from_letters(letters): # type: (List[np.array]) -> List[str] is_zero_classifier = inflate_classifier(SERIAL_IS_ZERO_CLASSIFIER_DIR) text = [] with PyTessBaseAPI() as api: api.SetVariable("load_system_dawg", "F") api.SetVariable("load_freq_dawg", "F") api.SetVariable("load_punc_dawg", "F") api.SetVariable("load_number_dawg", "F") api.SetVariable("load_unambig_dawg", "F") api.SetVariable("load_bigram_dawg", "F") api.SetVariable("load_fixed_length_dawgs", "F") api.SetVariable("classify_enable_learning", "F") api.SetVariable("classify_enable_adaptive_matcher", "F") api.SetVariable("segment_penalty_garbage", "F") api.SetVariable("segment_penalty_dict_nonword", "F") api.SetVariable("segment_penalty_dict_frequent_word", "F") api.SetVariable("segment_penalty_dict_case_ok", "F") api.SetVariable("segment_penalty_dict_case_bad", "F") api.SetVariable("edges_use_new_outline_complexity", "T") api.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") api.SetPageSegMode(PSM.SINGLE_CHAR) for letter in letters: if LABEL_TO_IS_ZERO[is_zero_classifier(letter)]: text.append("0") continue pil_image = Image.fromarray(letter) api.SetImage(pil_image) # show(np.array(api.GetThresholdedImage())) text.append(api.GetUTF8Text().replace("\n\n", "")) return text
def __init__(self): super(MemorySolver, self).__init__() self.button_classifier = inflate_classifier(BUTTONS_CLASSIFIER_DIR) self.screen_classifier = inflate_classifier(SCREEN_CLASSIFIER_DIR)
def __init__(self): super(PasswordSolver, self).__init__() self._letter_classifier = inflate_classifier( PASSWORD_LETTER_CLASSIFIER_DIR)
def test(): im = cv2.imread("/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0003.png") symbol_classifier = inflate_classifier(SYMBOLS_CLASSIFIER_DIR) symbols, positions = get_symbols_and_positions(im, symbol_classifier) print symbols order = get_symbol_order(symbols)
def __init__(self): super(SymbolsSolver, self).__init__() self._symbol_classifier = inflate_classifier(SYMBOLS_CLASSIFIER_DIR)
def __init__(self): super(PasswordSolver, self).__init__() self._letter_classifier = inflate_classifier(PASSWORD_LETTER_CLASSIFIER_DIR)