Layout and Text Visualization

layoutparser.visualization.draw_box(canvas, layout, box_width=None, color_map=None, show_element_id=False, id_font_size=None, id_font_path=None, id_text_color=None, id_text_background_color=None)[source]

Draw the layout region on the input canvas(image).

Parameters
  • canvas (ndarray or Image) – The canvas to draw the layout boxes.

  • layout (Layout or list) – The layout of the canvas to show.

  • box_width (int, optional) – Set to change the width of the drawn layout box boundary. Defaults to None, when the boundary is automatically calculated as the the DEFAULT_BOX_WIDTH_RATIO * the maximum of (height, width) of the canvas.

  • color_map (dict, optional) – A map from block.type to the colors, e.g., {1: ‘red’}. You can set it to {} to use only the DEFAULT_OUTLINE_COLOR for the outlines. Defaults to None, when a color palette is is automatically created based on the input layout.

  • show_element_id (bool, optional) – Whether to display block.id on the top-left corner of the block. Defaults to False.

  • id_font_size (int, optional) – Set to change the font size used for drawing block.id. Defaults to None, when the size is set to DEFAULT_FONT_SIZE.

  • id_font_path (str, optional) – Set to change the font used for drawing block.id. Defaults to None, when the DEFAULT_FONT_OBJECT is used.

  • id_text_color (str, optional) – Set to change the text color used for drawing block.id. Defaults to None, when the color is set to DEFAULT_TEXT_COLOR.

  • id_text_background_color (str, optional) – Set to change the text region background used for drawing block.id. Defaults to None, when the color is set to DEFAULT_TEXT_BACKGROUND.

Returns

A Image object containing the layout draw upon the input canvas.

Return type

PIL.Image.Image

layoutparser.visualization.draw_text(canvas, layout, arrangement='lr', font_size=None, font_path=None, text_color=None, text_background_color=None, vertical_text=False, with_box_on_text=False, text_box_width=None, text_box_color=None, with_layout=False, **kwargs)[source]

Draw the (detected) text in the layout according to their coordinates next to the input canvas (image) for better comparison.

Parameters
  • canvas (ndarray or Image) – The canvas to draw the layout boxes.

  • layout (Layout or list) – The layout of the canvas to show.

  • arrangement ({‘lr’, ‘ud’}, optional) –

    The arrangement of the drawn text canvas and the original image canvas: * lr - left and right * ud - up and down

    Defaults to ‘lr’.

  • font_size (str, optional) – Set to change the size of the font used for drawing block.text. Defaults to None, when the size is set to DEFAULT_FONT_SIZE.

  • font_path (str, optional) – Set to change the font used for drawing block.text. Defaults to None, when the DEFAULT_FONT_OBJECT is used.

  • text_color ([type], optional) – Set to change the text color used for drawing block.text. Defaults to None, when the color is set to DEFAULT_TEXT_COLOR.

  • text_background_color ([type], optional) – Set to change the text region background used for drawing block.text. Defaults to None, when the color is set to DEFAULT_TEXT_BACKGROUND.

  • vertical_text (bool, optional) – Whether the text in a block should be drawn vertically. Defaults to False.

  • with_box_on_text (bool, optional) – Whether to draw the layout box boundary of a text region on the text canvas. Defaults to False.

  • text_box_width (int, optional) – Set to change the width of the drawn layout box boundary. Defaults to None, when the boundary is automatically calculated as the the DEFAULT_BOX_WIDTH_RATIO * the maximum of (height, width) of the canvas.

  • text_box_color (int, optional) – Set to change the color of the drawn layout box boundary. Defaults to None, when the color is set to DEFAULT_OUTLINE_COLOR.

  • with_layout (bool, optional) – Whether to draw the layout boxes on the input (image) canvas. Defaults to False. When set to true, you can pass in the arguments in draw_box to change the style of the drawn layout boxes.

Returns

A Image object containing the drawn text from layout.

Return type

PIL.Image.Image