示例#1
0
def visual_test(directory, name, reverse=False):
    with open(os.path.join(directory, name + ".json")) as b:
        board = json.load(b)
    if reverse:
        board = reverse_board_state(board)
        name += "R"
    img = cv2.imread(os.path.join(directory, name + ".png"))
    # Create alpha channel
    alpha = 0.2 * np.ones((img.shape[0], img.shape[1], 1))
    extr = LabeledCellExtractor(alpha, board)
    vert, hori = extr.labeled_cells()
    for ((l, o), c) in vert + hori:
        if l is not None:
            c[:, :, :] = 1.0  # Modifies underlying alpha
    img = np.asarray(img * alpha, dtype=np.uint8)
    cv2.imshow(name, img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()