Shortcuts

BaseLocalVisualizer

class mmocr.visualization.BaseLocalVisualizer(name='visualizer', font_families='sans-serif', font_properties=None, **kwargs)[source]

The MMOCR Text Detection Local Visualizer.

Parameters
  • name (str) – Name of the instance. Defaults to ‘visualizer’.

  • image (np.ndarray, optional) – the origin image to draw. The format should be RGB. Defaults to None.

  • vis_backends (list, optional) – Visual backend config list. Default to None.

  • save_dir (str, optional) – Save file dir for all storage backends. If it is None, the backend storage will not save any data.

  • fig_save_cfg (dict) – Keyword parameters of figure for saving. Defaults to empty dict.

  • fig_show_cfg (dict) – Keyword parameters of figure for showing. Defaults to empty dict.

  • is_openset (bool, optional) – Whether the visualizer is used in OpenSet. Defaults to False.

  • font_families (Union[str, List[str]]) – The font families of labels. Defaults to ‘sans-serif’.

  • font_properties (Union[str, FontProperties], optional) – The font properties of texts. The format should be a path str to font file or a font_manager.FontProperties() object. If you want to draw Chinese texts, you need to prepare a font file that can show Chinese characters properly. For example: simhei.ttf,`simsun.ttc`,`simkai.ttf` and so on. Then set font_properties=matplotlib.font_manager.FontProperties (fname=’path/to/font_file’) or font_properties=’path/to/font_file’ This function need mmengine version >=0.6.0. Defaults to None.

Return type

None

get_bboxes_image(image, bboxes, colors='g', filling=False, line_width=0.5, alpha=0.5)[source]

Draw bboxes on image.

Parameters
  • image (np.ndarray) – The origin image to draw. The format should be RGB.

  • bboxes (Union[np.ndarray, torch.Tensor]) – The bboxes to draw.

  • colors (Union[str, Sequence[str]]) – The colors of bboxes. colors can have the same length with bboxes or just single value. If colors is single value, all the bboxes will have the same colors. Refer to matplotlib.colors for full list of formats that are accepted. Defaults to ‘g’.

  • filling (bool) – Whether to fill the bboxes. Defaults to False.

  • line_width (Union[int, float]) – The line width of bboxes. Defaults to 0.5.

  • alpha (float) – The alpha of bboxes. Defaults to 0.5.

  • self (mmengine.visualization.visualizer.Visualizer) –

Returns

The image with bboxes drawn.

Return type

np.ndarray

get_labels_image(image, labels, bboxes, colors='k', font_size=10, auto_font_size=False, font_families='sans-serif', font_properties=None)[source]

Draw labels on image.

Parameters
  • image (np.ndarray) – The origin image to draw. The format should be RGB.

  • labels (Union[np.ndarray, torch.Tensor]) – The labels to draw.

  • bboxes (Union[np.ndarray, torch.Tensor]) – The bboxes to draw.

  • colors (Union[str, Sequence[str]]) – The colors of labels. colors can have the same length with labels or just single value. If colors is single value, all the labels will have the same colors. Refer to matplotlib.colors for full list of formats that are accepted. Defaults to ‘k’.

  • font_size (Union[int, float]) – The font size of labels. Defaults to 10.

  • auto_font_size (bool) – Whether to automatically adjust font size. Defaults to False.

  • font_families (Union[str, List[str]]) – The font families of labels. Defaults to ‘sans-serif’.

  • font_properties (Union[str, FontProperties], optional) – The font properties of texts. The format should be a path str to font file or a font_manager.FontProperties() object. If you want to draw Chinese texts, you need to prepare a font file that can show Chinese characters properly. For example: simhei.ttf,`simsun.ttc`,`simkai.ttf` and so on. Then set font_properties=matplotlib.font_manager.FontProperties (fname=’path/to/font_file’) or font_properties=’path/to/font_file’. This function need mmengine version >=0.6.0. Defaults to None.

Return type

numpy.ndarray

get_polygons_image(image, polygons, colors='g', filling=False, line_width=0.5, alpha=0.5)[source]

Draw polygons on image.

Parameters
  • image (np.ndarray) – The origin image to draw. The format should be RGB.

  • polygons (Sequence[np.ndarray]) – The polygons to draw. The shape should be (N, 2).

  • colors (Union[str, Sequence[str]]) – The colors of polygons. colors can have the same length with polygons or just single value. If colors is single value, all the polygons will have the same colors. Refer to matplotlib.colors for full list of formats that are accepted. Defaults to ‘g’.

  • filling (bool) – Whether to fill the polygons. Defaults to False.

  • line_width (Union[int, float]) – The line width of polygons. Defaults to 0.5.

  • alpha (float) – The alpha of polygons. Defaults to 0.5.

Returns

The image with polygons drawn.

Return type

np.ndarray

Read the Docs v: dev-1.x
Versions
latest
stable
v1.0.1
v1.0.0
0.x
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
v0.1.0
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.