BaseLocalVisualizer¶
- class mmocr.visualization.BaseLocalVisualizer(name='visualizer', font_families='sans-serif', font_properties=None, **kwargs)[源代码]¶
The MMOCR Text Detection Local Visualizer.
- 参数
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.
- 返回类型
- get_bboxes_image(image, bboxes, colors='g', filling=False, line_width=0.5, alpha=0.5)[源代码]¶
Draw bboxes on image.
- 参数
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. Ifcolors
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.
- 返回
The image with bboxes drawn.
- 返回类型
np.ndarray
- get_labels_image(image, labels, bboxes, colors='k', font_size=10, auto_font_size=False, font_families='sans-serif', font_properties=None)[源代码]¶
Draw labels on image.
- 参数
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. Ifcolors
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.
- 返回类型
- get_polygons_image(image, polygons, colors='g', filling=False, line_width=0.5, alpha=0.5)[源代码]¶
Draw polygons on image.
- 参数
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. Ifcolors
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.
- 返回
The image with polygons drawn.
- 返回类型
np.ndarray