Add conversion to FEN

This commit is contained in:
2025-12-22 16:30:07 +01:00
parent 86dea774e4
commit 0aaea36586
12 changed files with 246 additions and 105 deletions

View File

@@ -1,13 +1,7 @@
import os
# --------------------------
# Configuration
# --------------------------
labels_dir = "datasets/visiope/test/labels"
labels_dir = "C:/Users/Laurent/Desktop/board-mate/rpi/training/datasets/edges/chess board detection 2.v2i.yolov11"
# --------------------------
# Process each label file
# --------------------------
for filename in os.listdir(labels_dir):
if not filename.endswith(".txt"):
continue

View File

@@ -1,7 +1,8 @@
import os
labels_dir = "../datasets/corners/Outer Chess Corners.v1i.yolov11/valid/labels"
label_to_be_removed = 1
labels_dir = "C:/Users/Laurent/Desktop/board-mate/rpi/training/datasets/edges/misis2025_cv_chess.v1i.yolov11/valid/labels"
labels_to_be_removed = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
for filename in os.listdir(labels_dir):
if not filename.endswith(".txt"):
@@ -20,13 +21,12 @@ for filename in os.listdir(labels_dir):
continue
cls = int(parts[0])
if cls == label_to_be_removed:
if cls in labels_to_be_removed:
print(f"{parts} found in {filename}")
continue
cls = 0
new_lines.append(" ".join([str(cls)] + parts[1:]))
# Overwrite file with updated indices
with open(txt_path, "w") as f:
f.write("\n".join(new_lines))

View File

@@ -2,15 +2,12 @@ import os
import shutil
def copy_images(src, dest):
image_extensions = [".jpg", ".jpeg", ".png", ".bmp", ".gif"]
def copy_files(src, dest):
for filename in os.listdir(src):
if any(filename.lower().endswith(ext) for ext in image_extensions):
src_path = os.path.join(src, filename)
dst_path = os.path.join(dest, filename)
shutil.copy2(src_path, dst_path)
src_path = os.path.join(src, filename)
dst_path = os.path.join(dest, filename)
shutil.copy2(src_path, dst_path)
def remap_labels(src, dest):
count = 0
@@ -41,8 +38,8 @@ def remap_labels(src, dest):
if __name__ == "__main__":
src_dir = "../datasets/pieces/visualizan/"
dest_dir = "../datasets/pieces/unified/"
src_dir = "../datasets/edges/misis2025_cv_chess.v1i.yolov11/"
dest_dir = "../datasets/edges/"
reference_classes = [
'w_pawn', 'w_knight', 'w_bishop', 'w_rook', 'w_queen', 'w_king',
@@ -67,5 +64,6 @@ if __name__ == "__main__":
dst_image_folder = os.path.normpath(os.path.join(dest_full_path, "images"))
dst_labels_folder = os.path.normpath(os.path.join(dest_full_path, "labels"))
copy_images(src_image_folder, dst_image_folder)
remap_labels(src_labels_folder, dst_labels_folder)
copy_files(src_image_folder, dst_image_folder)
copy_files(src_labels_folder, dst_labels_folder)
#remap_labels(src_labels_folder, dst_labels_folder)