def _test(): additional = [ # "/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-11 16.11.35.png", # "/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-11 16.09.07.png", "/Users/danny/Dropbox (Dropbox)/Screenshots/Screenshot 2017-02-11 16.28.04.png", ] for path in list(ls(DATA_DIR + "module_classifier/labelled/simon_says", 1)) + additional: im = cv2.imread(path) if "/Screenshots/" in path: from screenshot_helpers import MODULE_RECT height = im.shape[0] width = im.shape[1] x1, x2, y1, y2 = MODULE_RECT x1 = x1 * width / 100 x2 = x2 * width / 100 y1 = y1 * height / 100 y2 = y2 * height / 100 im = im[y1:y2, x1:x2] offset = (0, 0) color_to_position = get_square_positions(im, offset) for color, position in color_to_position.items(): cv2.circle(im, position, 10, (255, 0, 0)) show(im)
def solve_stored_mazes(): vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = \ get_classifier_directories(MODULE_CLASSIFIER_DIR) maze_dir = os.path.join(labelled_dir, "maze") files_to_test = ( "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0907.png", ) for i, file_name in enumerate(os.listdir(maze_dir)): # for file_name in files_to_test: # if file_name != "0023-full-bottom-left.png": # continue print file_name maze_image = cv2.imread(os.path.join(maze_dir, file_name)) lookup_key, start_coordinates, end_coordinates = get_maze_params( maze_image) print "lookup", lookup_key print "start (white)", start_coordinates print "end (red)", end_coordinates top, right, bottom, left = get_button_locations(maze_image) for location in (top, right, bottom, left): cv2.circle(maze_image, location, 10, (255, 0, 0), 10) show(maze_image) # print top, right, bottom, left moves = find_path_through_maze(lookup_key, start_coordinates, end_coordinates) print " ".join(moves)
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 test(): to_test = (1254, 1255) for path in ls_debug(*to_test): print "---------- NEXT IMAGE ------------" im = cv2.imread(path) get_connections(im) down_button = get_down_button(im) cv2.circle(im, down_button, 20, (255, 0, 0), 20) show(im)
def test(): images_to_test = ( "/Users/danny/Dropbox (Personal)/Projects/KeepTalkingBot/module_specific_data/debug/0530.png", ) for f in images_to_test: im = cv2.imread(f) right_arrow = find_arrows(im)[1] print right_arrow cv2.circle(im, right_arrow, 10, (255, 0, 0), 10) show(im)
def _test(): i = 0 for path in ls(DATA_DIR + "sides/batteries/raw_images"): # if "-left.png" not in path: # if "0030-edge-left.png" not in path: # continue i += 1 if i > 20: break # print path im = cv2.imread(path) from sides import _extract_side im = _extract_side(im, "-bottom" in path) print get_batteries_count_for_side(im) show(im, .25)
def manually_group_images(classifier_dir): vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = get_classifier_directories(classifier_dir) for file_path in ls(unlabelled_dir): folder_name = chr(show(cv2.imread(file_path))) folder = os.path.join(labelled_dir, folder_name) if not os.path.exists(folder): os.makedirs(folder) dst = os.path.join(labelled_dir, folder, os.path.basename(file_path)) shutil.copyfile(file_path, dst)
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 manually_group_images(classifier_dir): vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = get_classifier_directories( classifier_dir) for file_path in ls(unlabelled_dir): folder_name = chr(show(cv2.imread(file_path))) folder = os.path.join(labelled_dir, folder_name) if not os.path.exists(folder): os.makedirs(folder) dst = os.path.join(labelled_dir, folder, os.path.basename(file_path)) shutil.copyfile(file_path, dst)
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 _test(): for path in ls(DATA_DIR + "module_classifier/labelled/simple_wires", 5): im = cv2.imread(path) sides_info = SidesInfo(2, ["A", "B", "C", "D", "E", "2"]) positions, colors = get_wire_positions_and_colors(im) index_to_cut = get_wire_index_to_cut(colors, sides_info) color = colors[index_to_cut] x, y = positions[index_to_cut] radius = int(float(get_width(im) * 5) / 100.0) circle_colors = { WireColor.black: (0, 0, 0), WireColor.white: (255, 255, 255), WireColor.blue: (255, 0, 0), WireColor.red: (0, 0, 255), WireColor.yellow: (0, 255, 255), } cv2.circle(im, (x, y), radius, circle_colors[color]) show(im)
def sort_sides(): for path in ls(RAW_ORIG_SCREENSHOTS): sequence_id = int(os.path.basename(path).split("-")[0]) if sequence_id <= 27 or sequence_id % 3 != 0: continue print path im = cv2.imread(path) height, width = im.shape[:2] key = show(cv2.resize(im, (width / 4, height / 4))) if key == ord("y"): print "COPYING " shutil.copy(path, os.path.join(EDGE_INDICATORS_SCREENSHOTS, os.path.basename(path)))
def _test(): vocab_path, unlabelled_dir, labelled_dir, features_dir, svm_data_dir = \ get_classifier_directories(SERIAL_IS_ZERO_CLASSIFIER_DIR) letter_idx = 0 i = 0 group = 0 found_in_group = 0 # for path in ls(DATA_DIR + "module_classifier/unlabelled"): for path in ls_debug(1294, 1297): # if "-left.png" not in path: # if "0036-edge-bottom.png" not in path: # continue # new_group = int(os.path.basename(path).split("-")[0]) # if new_group % 3 != 0: # continue # if new_group != group: # if found_in_group != 1: # "!!!! Found {} in group {} !!!!".format(found_in_group, group) # found_in_group = 0 # group = new_group i += 1 # if i == 1: # continue # if i > 1: # break print path im = cv2.imread(path) from sides import _extract_side im = _extract_side(im, "-bottom" in path) text = get_serial_number_from_side(im) if text is None: print "NO SERIAL NUMBER" else: print "-".join(text) text_threshold = _get_cleaned_up_text_subsection(im) if text_threshold is not None: show(text_threshold)
def sort_sides(): for path in ls(RAW_ORIG_SCREENSHOTS): sequence_id = int(os.path.basename(path).split("-")[0]) if sequence_id <= 27 or sequence_id % 3 != 0: continue print path im = cv2.imread(path) height, width = im.shape[:2] key = show(cv2.resize(im, (width / 4, height / 4))) if key == ord("y"): print "COPYING " shutil.copy( path, os.path.join(EDGE_INDICATORS_SCREENSHOTS, os.path.basename(path)))