def load_board(board_image_file_name):
"""
Parse the input board screenshot into a Board object.
:param board_image_file_name: Path to the screenshot of the board.
:return: A Board instance representing the input board.
"""
img = cv2.imread(board_image_file_name, cv2.IMREAD_COLOR)
coordinate_map = {}
for i in range(10):
for j in range(10):
pixel_i = IMAGE_BLOCK_START_I + i * IMAGE_BLOCK_OFFSET
pixel_j = IMAGE_BLOCK_START_J + j * IMAGE_BLOCK_OFFSET
bgr = img[pixel_i][pixel_j]
color_code = struct.pack('BBB', *bgr).encode('hex')
if color_code == 'e4eff7':
coordinate_map[Coordinate(i, j)] = EmptyColor()
else:
coordinate_map[Coordinate(i, j)] = Color(color_code)
return Board.from_coordinate_map(coordinate_map)
评论列表
文章目录