def callout_info()

in web-app-pix2info-python/src/backend/render.py [0:0]


def callout_info(demo: Demo) -> Iterator[CalloutInfo]:
    font = demo.font_median
    if font is None:
        return

    callout_info_gens = []
    if demo.options.barcodes:
        callout_info_gens.append(callout_info_for_barcodes(demo))
    if demo.options.entities:
        callout_info_gens.append(callout_info_for_entities(demo))
    if not callout_info_gens:
        return

    box_x = demo.page_crop_box[2] + demo.text_height_median
    box_y = demo.page_crop_box[1] + CROP_MARGIN
    offset_y = demo.text_height_median * 2
    box_padding = demo.text_padding * 2

    colors = color_gen()
    for callout_info_gen in callout_info_gens:
        for vertices, text, confidence in callout_info_gen:
            text = text.replace("\n", "\\n")  # Show new line characters
            text_size = font.getsize(text)
            box_w, box_h = text_size[0] + box_padding, text_size[1] + box_padding
            rect = (box_x, box_y, box_x + box_w, box_y + box_h)
            text_xy = (box_x + demo.text_padding, box_y + demo.text_padding)
            box_y += offset_y
            if confidence is None or confident_enough(confidence):
                bg_color = DEFAULT_BG_COLOR
                fg_color = next(colors)
            else:
                bg_color = color_transparent_like_a_highlighter(DEFAULT_BG_COLOR)
                fg_color = LOW_CONFIDENCE_BG_COLOR

            yield vertices, text, rect, text_xy, bg_color, fg_color