Working state, with single images regeneration and better notes detection
This commit is contained in:
@@ -110,6 +110,8 @@ def process_student(args):
|
||||
|
||||
label_images = []
|
||||
all_checkboxes = []
|
||||
bnote_entries = [] # For bnote.json
|
||||
|
||||
sorted_labels = sorted(labels.items(), key=lambda x: natural_key(x[0]))
|
||||
|
||||
for label, content in sorted_labels:
|
||||
@@ -122,7 +124,7 @@ def process_student(args):
|
||||
cb_renderer = CheckboxRenderer(label)
|
||||
|
||||
# Render using the shared engine
|
||||
final_img = annotating.compose_label_image(
|
||||
final_img, header_h = annotating.compose_label_image(
|
||||
base_img, label, content['result'], content['coordinates'][0],
|
||||
render_fn=safe_render_latex,
|
||||
draw_callback=cb_renderer.callback
|
||||
@@ -130,6 +132,13 @@ def process_student(args):
|
||||
|
||||
label_images.append(final_img)
|
||||
all_checkboxes.append(cb_renderer.checkboxes)
|
||||
bnote_entries.append({
|
||||
"id": student_id,
|
||||
"label": label,
|
||||
"header_height": header_h,
|
||||
# hmin/hmax will be filled during concatenation
|
||||
"img_h": final_img.height
|
||||
})
|
||||
|
||||
if not label_images: return
|
||||
|
||||
@@ -141,9 +150,13 @@ def process_student(args):
|
||||
final_json_map = []
|
||||
current_y = 0
|
||||
|
||||
for img, boxes in zip(label_images, all_checkboxes):
|
||||
for idx, (img, boxes) in enumerate(zip(label_images, all_checkboxes)):
|
||||
concat_img.paste(img, (0, current_y))
|
||||
|
||||
bnote_entries[idx]["hmin"] = current_y
|
||||
bnote_entries[idx]["hmax"] = current_y + img.height
|
||||
del bnote_entries[idx]["img_h"] # Clean up temp data
|
||||
|
||||
# Adjust coordinates for concatenated image
|
||||
for item in boxes:
|
||||
# item might have 'rel_box' (header) or 'final_box' (local)
|
||||
@@ -154,6 +167,14 @@ def process_student(args):
|
||||
|
||||
current_y += img.height
|
||||
|
||||
bnote_data = {
|
||||
"width": max_w,
|
||||
"height": total_h,
|
||||
"images": bnote_entries
|
||||
}
|
||||
with open(os.path.join(output_dir, "bnote.json"), "w") as f:
|
||||
json.dump(bnote_data, f, indent=2)
|
||||
|
||||
with open(os.path.join(output_dir, "checkboxes.json"), "w") as f:
|
||||
json.dump(final_json_map, f, indent=2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user