This commit is contained in:
sebastien committed 2026-10-23 08:24:10 +02:00
1 parent c30aac0572
commit 834ffe32f2
7 files changed
+116 -14

No files matched your search

+17 -9
View File
@@ -416,6 +416,7 @@ def compose_label_image(base_img, label, result, hmin,
# Draw Headers
current_y = 0
draw = ImageDraw.Draw(final_img, "RGBA")
callback_items = []
for el in header_elements:
if el["type"] == "score" and more_right:
@@ -426,9 +427,9 @@ def compose_label_image(base_img, label, result, hmin,
if draw_callback:
# Hook for checkboxes
draw_callback("header_item", draw,
{"x": 0, "y": current_y, "w": el["img"].width, "h": el["img"].height},
el)
callback_items.append(("header_item",
{"x": 0, "y": current_y, "w": el["img"].width, "h": el["img"].height},
el))
current_y += el["img"].height
# Paste Base Image
@@ -453,9 +454,9 @@ def compose_label_image(base_img, label, result, hmin,
draw.rectangle([target_xmin, target_ymin, target_xmax, target_ymax], outline="red", width=3)
if draw_callback:
draw_callback("local_rect", draw,
{"box": [target_xmin, target_ymin, target_xmax, target_ymax]},
{"data": fb, "index": idx})
callback_items.append(("local_rect",
{"box": [target_xmin, target_ymin, target_xmax, target_ymax]},
{"data": fb, "index": idx}))
# Render Text
txt_img = render_fn(fb['text'], width_px=ANNOT_WIDTH,
@@ -481,12 +482,19 @@ def compose_label_image(base_img, label, result, hmin,
final_img.paste(txt_img, (10, int(paste_y)), mask=txt_img)
if draw_callback:
draw_callback("local_text", draw,
{"x": 10, "y": int(paste_y), "w": txt_img.width, "h": txt_img.height},
{"data": fb, "index": idx})
callback_items.append(("local_text",
{"x": 10, "y": int(paste_y), "w": txt_img.width, "h": txt_img.height},
{"data": fb, "index": idx}))
last_text_bottom = paste_y + txt_img.height
# Keep checkbox interiors clear of later rectangles and comment images.
# Use the final canvas, which may have grown while placing comments.
if draw_callback:
draw = ImageDraw.Draw(final_img, "RGBA")
for kind, pos, meta in callback_items:
draw_callback(kind, draw, pos, meta)
final_img.info['annotation_layout'] = layout
return final_img, header_height