agrobot_base/Python/yolov8-seg/make_empty_labels.py

52 lines
1.3 KiB
Python
Raw Permalink Normal View History

2026-02-24 13:38:14 +00:00
from pathlib import Path
# ==============================
# CONFIGURE AQUI
# ==============================
IMAGES_DIR = Path("images/chao") # <-- ALTERAR
OVERWRITE = False # True para sobrescrever labels existentes
# ==============================
def main():
if not IMAGES_DIR.exists():
print(f"[ERRO] Pasta não encontrada: {IMAGES_DIR}")
return
labels_dir = IMAGES_DIR / "labels"
labels_dir.mkdir(exist_ok=True)
image_extensions = {".jpg", ".jpeg", ".png"}
images = [
f for f in IMAGES_DIR.iterdir()
if f.suffix.lower() in image_extensions
]
if not images:
print("[INFO] Nenhuma imagem encontrada.")
return
criados = 0
ignorados = 0
for img in images:
label_path = labels_dir / (img.stem + ".txt")
if label_path.exists() and not OVERWRITE:
ignorados += 1
continue
label_path.write_text("") # cria arquivo vazio
criados += 1
print("===================================")
print(f"Imagens encontradas: {len(images)}")
print(f"Labels criados: {criados}")
print(f"Labels ignorados: {ignorados}")
print("Pasta labels:", labels_dir)
print("===================================")
if __name__ == "__main__":
main()