diff --git a/arial.ttf b/arial.ttf new file mode 100644 index 0000000..886789b Binary files /dev/null and b/arial.ttf differ diff --git a/debug.py b/debug.py index 57bf27e..dcdab81 100644 --- a/debug.py +++ b/debug.py @@ -3,18 +3,37 @@ import os import time import subprocess import config +from PIL import ImageFont def draw_boxes(page, boxes): im = debug_im(page) + #for i in boxes: + # continue + # i["y0"] = page.height - i["y0"] + # i["y1"] = page.height - i["y1"] + # #i["x0"] *= im.original.height / page.height + # #i["x1"] *= im.original.height / page.height + # #i["y0"] *= im.original.height / page.height + # #i["y1"] *= im.original.height / page.height for box in boxes: - im.draw_line(((box["x0"], page.height - box["y0"]), (box["x1"], page.height - box["y0"]))) - im.draw_line(((box["x1"], page.height - box["y0"]), (box["x1"], page.height - box["y1"]))) - im.draw_line(((box["x1"], page.height - box["y1"]), (box["x0"], page.height - box["y1"]))) - im.draw_line(((box["x0"], page.height - box["y1"]), (box["x0"], page.height - box["y0"]))) + im.draw_line(((box["x0"], box["y0"]), (box["x1"], box["y0"]))) + im.draw_line(((box["x1"], box["y0"]), (box["x1"], box["y1"]))) + im.draw_line(((box["x1"], box["y1"]), (box["x0"], box["y1"]))) + im.draw_line(((box["x0"], box["y1"]), (box["x0"], box["y0"]))) if "debug_label" in box: + font = ImageFont.truetype("arial.ttf", 24) + for offset in [-2, -1, 1, 2]: + im.draw.text( + xy=(offset + box["x0"] * im.original.height / page.height, offset + box["y0"] * im.original.height / page.height), + text=str(box["debug_label"]), + fill=(255,255,255), + font=font, + ) im.draw.text( - xy=(box["x0"], page.height-box["y0"]), + xy=(box["x0"] * im.original.height / page.height, box["y0"] * im.original.height / page.height), text=str(box["debug_label"]), + fill=(0,255,0), + font=font, ) debug_show(im)