MCPcopy Index your code
hub / github.com/Layout-Parser/layout-parser / draw_text

Function draw_text

src/layoutparser/visualization.py:418–571  ·  view source on GitHub ↗

Draw the (detected) text in the `layout` according to their coordinates next to the input `canvas` (image) for better comparison. Args: canvas (:obj:`~np.ndarray` or :obj:`~PIL.Image.Image`): The canvas to draw the layout boxes. layout (:obj:`Layout` or :obj:`lis

(
    canvas,
    layout,
    arrangement: str = "lr",
    font_size: Optional[int] = None,
    font_path: Optional[str] = None,
    text_color: Optional[str] = None,
    text_background_color: Optional[str] = None,
    text_background_alpha: Optional[float] = None,
    vertical_text: bool = False,
    with_box_on_text: bool = False,
    text_box_width: Optional[int] = None,
    text_box_color: Optional[str] = None,
    text_box_alpha: Optional[float] = None,
    with_layout: bool = False,
    **kwargs,
)

Source from the content-addressed store, hash-verified

416
417@image_loader
418def draw_text(
419 canvas,
420 layout,
421 arrangement: str = "lr",
422 font_size: Optional[int] = None,
423 font_path: Optional[str] = None,
424 text_color: Optional[str] = None,
425 text_background_color: Optional[str] = None,
426 text_background_alpha: Optional[float] = None,
427 vertical_text: bool = False,
428 with_box_on_text: bool = False,
429 text_box_width: Optional[int] = None,
430 text_box_color: Optional[str] = None,
431 text_box_alpha: Optional[float] = None,
432 with_layout: bool = False,
433 **kwargs,
434):
435 """Draw the (detected) text in the `layout` according to
436 their coordinates next to the input `canvas` (image) for better comparison.
437
438 Args:
439 canvas (:obj:`~np.ndarray` or :obj:`~PIL.Image.Image`):
440 The canvas to draw the layout boxes.
441 layout (:obj:`Layout` or :obj:`list`):
442 The layout of the canvas to show.
443 arrangement (`{'lr', 'ud'}`, optional):
444 The arrangement of the drawn text canvas and the original
445 image canvas:
446 * `lr` - left and right
447 * `ud` - up and down
448 Defaults to 'lr'.
449 font_size (:obj:`str`, optional):
450 Set to change the size of the font used for
451 drawing `block.text`.
452 Defaults to None, when the size is set to
453 :const:`DEFAULT_FONT_SIZE`.
454 font_path (:obj:`str`, optional):
455 Set to change the font used for drawing `block.text`.
456 Defaults to None, when the :const:`DEFAULT_FONT_OBJECT` is used.
457 text_color ([type], optional):
458 Set to change the text color used for drawing `block.text`.
459 Defaults to None, when the color is set to
460 :const:`DEFAULT_TEXT_COLOR`.
461 text_background_color ([type], optional):
462 Set to change the text region background used for drawing
463 `block.text`.
464 Defaults to None, when the color is set to
465 :const:`DEFAULT_TEXT_BACKGROUND`.
466 text_background_alpha (:obj:`float`, optional):
467 A float range from 0 to 1. Set to change the alpha of the
468 background of the canvas.
469 Defaults to 1 - the text box will be solid.
470 vertical_text (bool, optional):
471 Whether the text in a block should be drawn vertically.
472 Defaults to False.
473 with_box_on_text (bool, optional):
474 Whether to draw the layout box boundary of a text region
475 on the text canvas.

Callers 1

test_vizFunction · 0.85

Calls 9

draw_boxFunction · 0.85
_create_font_objectFunction · 0.85
_create_new_canvasFunction · 0.85
_get_color_rgbFunction · 0.85
_draw_vertical_textFunction · 0.85
padMethod · 0.45

Tested by 1

test_vizFunction · 0.68