Views
No views yet
1from src.chess_board_detection.yolo.segmentation.segmentation_model import ChessBoardSegmentationModel
2
3# Load the model
4model = ChessBoardSegmentationModel(model_path="path/to/downloaded/model.pt")
5
6# Get polygon coordinates for a chessboard
7polygon_info, is_valid = model.get_polygon_coordinates("path/to/chessboard_image.jpg")
8
9if is_valid:
10 print(f"Detected chessboard polygon: {polygon_info}")
11
12 # Extract corners from the segmentation
13 corners = model.extract_corners_from_segmentation(
14 "path/to/chessboard_image.jpg",
15 polygon_info
16 )
17 print(f"Extracted corners: {corners}")
18
19# Visualize results
20model.plot_eval("path/to/chessboard_image.jpg", show=True)1from ultralytics import YOLO
2
3# Load the model
4model = YOLO("path/to/downloaded/model.pt")
5
6# Run segmentation
7results = model("path/to/chessboard_image.jpg")
8
9# Get masks and polygons
10for result in results:
11 if result.masks is not None:
12 for mask in result.masks:
13 polygon = mask.xy[0] # Polygon coordinates
14 print(f"Polygon points: {polygon}")1# data.yaml
2train: path/to/train/images
3val: path/to/val/images
4nc: 1
5names: ['chessboard']# labels/image.txt
0 x1 y1 x2 y2 x3 y3 x4 y4 ... # normalized coordinates1python src/chess_board_detection/yolo/segmentation/train_segmentation.py \
2 --data data/chessboard_segmentation/chess-board-3/data.yaml \
3 --epochs 100 \
4 --batch 16 \
5 --pretrained-model yolov8s-seg.pt1@misc{dopaul_chess_board_segmentation,
2 title={chess_board_segmentation},
3 author={dopaul},
4 year={2024},
5 publisher={Hugging Face},
6 url={https://huggingface.co/dopaul/chess_board_segmentation}
7}