Working state for annotating
parent
194e0c867b
commit
7ea5cbc1e5
|
|
@ -4,7 +4,8 @@ import json
|
||||||
import glob
|
import glob
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
MARGIN_LEFT = 200
|
MARGIN_LEFT = 300
|
||||||
|
ANNOT_WIDTH = 600
|
||||||
|
|
||||||
# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates}
|
# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates}
|
||||||
# Coordinates are the real coordinates (hmin, hmax) of the image in the Group
|
# Coordinates are the real coordinates (hmin, hmax) of the image in the Group
|
||||||
|
|
@ -198,7 +199,7 @@ def render_latex_text(text, width_px, bg_color=(255, 255, 255, 255), max_lines=N
|
||||||
final_img.alpha_composite(img)
|
final_img.alpha_composite(img)
|
||||||
return final_img
|
return final_img
|
||||||
|
|
||||||
def process_correction(root_dir, data, all_labels):
|
def process_correction(root_dir, data, all_labels, overwrite=False):
|
||||||
for student_id, labels in data.items():
|
for student_id, labels in data.items():
|
||||||
|
|
||||||
# Prepare output directory: Dir/Anot_CopieID
|
# Prepare output directory: Dir/Anot_CopieID
|
||||||
|
|
@ -208,7 +209,7 @@ def process_correction(root_dir, data, all_labels):
|
||||||
|
|
||||||
# Check if already processed (Concat.jpg exists)
|
# Check if already processed (Concat.jpg exists)
|
||||||
concat_path = os.path.join(output_dir, "Concat.jpg")
|
concat_path = os.path.join(output_dir, "Concat.jpg")
|
||||||
if os.path.exists(concat_path):
|
if os.path.exists(concat_path) and not overwrite:
|
||||||
print(f"Skipping Copie {student_id} (Concat.jpg exists)")
|
print(f"Skipping Copie {student_id} (Concat.jpg exists)")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -323,7 +324,7 @@ def process_correction(root_dir, data, all_labels):
|
||||||
# (255, 0, 0, 50) is transparent red
|
# (255, 0, 0, 50) is transparent red
|
||||||
txt_img = render_latex_text(
|
txt_img = render_latex_text(
|
||||||
fb['text'],
|
fb['text'],
|
||||||
width_px=600,
|
width_px=ANNOT_WIDTH,
|
||||||
bg_color=(255, 200, 200, 180), # Light Red semi-transparent
|
bg_color=(255, 200, 200, 180), # Light Red semi-transparent
|
||||||
max_lines=3
|
max_lines=3
|
||||||
)
|
)
|
||||||
|
|
@ -403,16 +404,17 @@ def concat_display_image(subdir):
|
||||||
# subprocess.call(('xdg-open', save_path))
|
# subprocess.call(('xdg-open', save_path))
|
||||||
|
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Annotate copies")
|
||||||
|
parser.add_argument("root_dir", help="Directory containing the copies")
|
||||||
|
parser.add_argument("--overwrite", action="store_true", help="Reprocess even if Concat.jpg exists")
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
args = parser.parse_args()
|
||||||
print("Usage: python script.py <Dir>")
|
root_dir = args.root_dir
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
root_dir = sys.argv[1]
|
|
||||||
labels = list(filter(None, (Path(root_dir) / "labels").read_text().splitlines()))
|
labels = list(filter(None, (Path(root_dir) / "labels").read_text().splitlines()))
|
||||||
results = make_dictionary(root_dir)
|
results = make_dictionary(root_dir)
|
||||||
# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates}
|
# Results is : Copie id -> label -> {pdf_path, gemini_result, coordinates}
|
||||||
# Coordinates are the real coordinates (hmin, hmax) of the image in the Group
|
# Coordinates are the real coordinates (hmin, hmax) of the image in the Group
|
||||||
# print(results,"\n\n\n")
|
# print(results,"\n\n\n")
|
||||||
process_correction(root_dir, results, labels)
|
process_correction(root_dir, results, labels,overwrite=args.overwrite)
|
||||||
# concat_anot_images(root_dir)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue