Unverified Commit 940609d5 authored by SuperDong's avatar SuperDong Committed by GitHub
Browse files

[Enhancement] Add type annoations for mmcv/visualization/image (#1946)



* dev_1st_mmcv_visual_image_py

* dev_3rd_mmcv_visual_image_py

* dev_4th_mmcv_visual_image_py

* dev_5th_mmcv_visual_image_py

* dev_6th_mmcv_visual_image_py

* dev_7th_mmcv_visual_image_py

* dev_8th_mmcv_visual_image_py

* dev_9th_mmcv_visual_image_py

* minor fix

* fix isort
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
parent 94cc99d5
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
from typing import List, Optional, Union
import cv2 import cv2
import numpy as np import numpy as np
from mmcv.image import imread, imwrite from mmcv.image import imread, imwrite
from .color import color_val from .color import Color, color_val
# a type alias declares the optional types of color argument
ColorType = Union[Color, str, tuple, int, np.ndarray]
def imshow(img, win_name='', wait_time=0): def imshow(img: Union[str, np.ndarray],
win_name: str = '',
wait_time: int = 0):
"""Show an image. """Show an image.
Args: Args:
...@@ -27,21 +34,21 @@ def imshow(img, win_name='', wait_time=0): ...@@ -27,21 +34,21 @@ def imshow(img, win_name='', wait_time=0):
ret = cv2.waitKey(wait_time) ret = cv2.waitKey(wait_time)
def imshow_bboxes(img, def imshow_bboxes(img: Union[str, np.ndarray],
bboxes, bboxes: Union[list, np.ndarray],
colors='green', colors: ColorType = 'green',
top_k=-1, top_k: int = -1,
thickness=1, thickness: int = 1,
show=True, show: bool = True,
win_name='', win_name: str = '',
wait_time=0, wait_time: int = 0,
out_file=None): out_file: Optional[str] = None):
"""Draw bboxes on an image. """Draw bboxes on an image.
Args: Args:
img (str or ndarray): The image to be displayed. img (str or ndarray): The image to be displayed.
bboxes (list or ndarray): A list of ndarray of shape (k, 4). bboxes (list or ndarray): A list of ndarray of shape (k, 4).
colors (list[str or tuple or Color]): A list of colors. colors (Color or str or tuple or int or ndarray): A list of colors.
top_k (int): Plot the first k bboxes only if set positive. top_k (int): Plot the first k bboxes only if set positive.
thickness (int): Thickness of lines. thickness (int): Thickness of lines.
show (bool): Whether to show the image. show (bool): Whether to show the image.
...@@ -81,19 +88,19 @@ def imshow_bboxes(img, ...@@ -81,19 +88,19 @@ def imshow_bboxes(img,
return img return img
def imshow_det_bboxes(img, def imshow_det_bboxes(img: Union[str, np.ndarray],
bboxes, bboxes: np.ndarray,
labels, labels: np.ndarray,
class_names=None, class_names: List[str] = None,
score_thr=0, score_thr: float = 0,
bbox_color='green', bbox_color: ColorType = 'green',
text_color='green', text_color: ColorType = 'green',
thickness=1, thickness: int = 1,
font_scale=0.5, font_scale: float = 0.5,
show=True, show: bool = True,
win_name='', win_name: str = '',
wait_time=0, wait_time: int = 0,
out_file=None): out_file: Optional[str] = None):
"""Draw bboxes and class labels (with scores) on an image. """Draw bboxes and class labels (with scores) on an image.
Args: Args:
...@@ -103,8 +110,10 @@ def imshow_det_bboxes(img, ...@@ -103,8 +110,10 @@ def imshow_det_bboxes(img,
labels (ndarray): Labels of bboxes. labels (ndarray): Labels of bboxes.
class_names (list[str]): Names of each classes. class_names (list[str]): Names of each classes.
score_thr (float): Minimum score of bboxes to be shown. score_thr (float): Minimum score of bboxes to be shown.
bbox_color (str or tuple or :obj:`Color`): Color of bbox lines. bbox_color (Color or str or tuple or int or ndarray): Color
text_color (str or tuple or :obj:`Color`): Color of texts. of bbox lines.
text_color (Color or str or tuple or int or ndarray): Color
of texts.
thickness (int): Thickness of lines. thickness (int): Thickness of lines.
font_scale (float): Font scales of texts. font_scale (float): Font scales of texts.
show (bool): Whether to show the image. show (bool): Whether to show the image.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment