def save_binary_list(number_binary_list, family_name, target_path, target_suffix, types): type_count = len(types) number_count = int(len(number_binary_list) / type_count) result_list = [] for index, cur_type in enumerate(types): for num in range(number_count): num_file_name = os.path.join(target_path, "_".join((str(num), cur_type, family_name))+target_suffix ) cv2_helper.save_binary_pic_txt( num_file_name, number_binary_list[index*number_count + num]) result_list.append(num_file_name) return result_list
ORIGINAL_IMAGE_NAME = './images/antiqua.png' gray_pic = cv2.imread(ORIGINAL_IMAGE_NAME, 0) color_pic = cv2.imread(ORIGINAL_IMAGE_NAME) with test("find_numbers_rectangles"): threshed_pic_array = cv2_helper.threshold_white_with_mean_percent(gray_pic) numbers_rectangles = find_numbers_rectangles(threshed_pic_array) numbers_rectangles.size().must_equal(40) # cv2_helper.show_contours_in_pic(color_pic,numbers_rectangles) # other_pic = cv2.imread('./images/verdana.png', 0) # number_binary_ragions = find_font_number_binary_ragions(other_pic) # threshed_pic_array = cv2_helper.threshold_white_with_mean_percent(gray_pic) # numbers_rectangles = find_numbers_rectangles(threshed_pic_array) # numbers_rectangles.size().must_equal(40) # cv2_helper.show_contours_in_pic(cv2.imread('./images/verdana.png'),numbers_rectangles) with test("find_font_number_binary_ragions"): test_file_path = 'test_resources/test.dataset' number_binary_ragions = find_font_number_binary_ragions(gray_pic) cv2_helper.save_binary_pic_txt(test_file_path, number_binary_ragions[0]) numpy.savetxt(test_file_path, number_binary_ragions[0], fmt='%d', delimiter='') # other_pic = cv2.imread('./images/verdana.png', 0) # number_binary_ragions = find_font_number_binary_ragions(other_pic) # cv2_helper.save_binary_pic_txt(test_file_path, number_binary_ragions[0]) pass