Consistent all_labels reading

master
Sébastien Miquel 2026-02-26 09:02:08 +01:00
parent f384121e9b
commit 48327fbd27
3 changed files with 18 additions and 5 deletions

View File

@ -319,7 +319,9 @@ if __name__ == "__main__":
files_to_process = sorted(cutleft_dir.glob("*.jpg")) files_to_process = sorted(cutleft_dir.glob("*.jpg"))
try: try:
all_labels = list(filter(None, (base_dir / "labels").read_text().splitlines())) all_labels = sorted(list(filter(None,
(base_dir / "labels").read_text().splitlines())),
key = natural_key)
except FileNotFoundError: except FileNotFoundError:
all_labels = [] all_labels = []

View File

@ -158,7 +158,7 @@ def has_significant_notes(note_img, threshold=20):
print(f"Debug : visible pixels is {visible_pixels}") print(f"Debug : visible pixels is {visible_pixels}")
return visible_pixels > threshold return visible_pixels > threshold
def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_layer): def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_layer, all_labels):
""" """
Modifies data based on actions, reads bnote.json, cuts notes, Modifies data based on actions, reads bnote.json, cuts notes,
regenerates all label images for consistency, saves dirty ones, regenerates all label images for consistency, saves dirty ones,
@ -221,7 +221,7 @@ def apply_actions_and_regenerate(root_dir, data, student_id, actions, notes_laye
# --- 2. Process Images (Cut notes, Regenerate, Concatenate) --- # --- 2. Process Images (Cut notes, Regenerate, Concatenate) ---
concat_list = [] concat_list = []
d_notes = {} d_notes = dict.fromkeys(all_labels, "")
# Iterate over images defined in bnote.json to maintain order/geometry # Iterate over images defined in bnote.json to maintain order/geometry
for img_info in bnote_data.get("images", []): for img_info in bnote_data.get("images", []):
@ -289,6 +289,14 @@ if __name__ == "__main__":
root_dir = sys.argv[1] root_dir = sys.argv[1]
try:
all_labels = sorted(list(filter(None,
(Path(root_dir) / "labels")
.read_text().splitlines())),
key = natural_key)
except FileNotFoundError:
all_labels = []
# Load original data # Load original data
original_data = annotating.make_dictionary(root_dir) original_data = annotating.make_dictionary(root_dir)
@ -299,6 +307,6 @@ if __name__ == "__main__":
print(f"Processing annotations for: {student_id}") print(f"Processing annotations for: {student_id}")
actions, notes = detect_checks_and_notes(bnot_dir) actions, notes = detect_checks_and_notes(bnot_dir)
if actions or notes: if actions or notes:
apply_actions_and_regenerate(root_dir, original_data, student_id, actions, notes) apply_actions_and_regenerate(root_dir, original_data, student_id, actions, notes, all_labels)
else: else:
print(" No changes detected or missing files.") print(" No changes detected or missing files.")

View File

@ -15,7 +15,10 @@ def main():
else: else:
work_dir = os.path.abspath(sys.argv[1]) work_dir = os.path.abspath(sys.argv[1])
all_labels = [l for l in (Path(work_dir) / "labels").read_text().split("\n") if l!=""] all_labels = sorted(list(filter(None,
(Path(work_dir) / "labels")
.read_text().splitlines())),
key = natural_key)
a_rendre_path = os.path.join(work_dir, TARGET_DIR_NAME) a_rendre_path = os.path.join(work_dir, TARGET_DIR_NAME)
if not os.path.isdir(a_rendre_path): if not os.path.isdir(a_rendre_path):