mindspore.dataset.utils.imshow_det_bbox

View Source On Gitee
mindspore.dataset.utils.imshow_det_bbox(image, bboxes, labels, segm=None, class_names=None, score_threshold=0, bbox_color=(0, 255, 0), text_color=(203, 192, 255), mask_color=(128, 0, 128), thickness=2, font_size=0.8, show=True, win_name='win', wait_time=2000, out_file=None)[source]

Draw an image with given bboxes and class labels (with scores).

Parameters
  • image (numpy.ndarray) – The image to be displayed, shaped \(<C, H, W>\) or \(<H, W, C>\), formatted RGB.

  • bboxes (numpy.ndarray) – Bounding boxes (with scores), shaped \(<N, 4>\) or \(<N, 5>\), data should be ordered with <N, x, y, w, h>.

  • labels (numpy.ndarray) – Labels of bboxes, shaped \(<N, 1>\).

  • segm (numpy.ndarray) – The segmentation masks of image in M classes, shaped \(<M, H, W>\). Default: None.

  • class_names (list[str], tuple[str], dict) – Names of each class to map label to class name. Default: None, only display label.

  • score_threshold (float) – Minimum score of bboxes to be shown. Default: 0.

  • bbox_color (tuple(int)) – Color of bbox lines. The tuple of color should be in BGR order. Default: (0, 255 ,0), means 'green'.

  • text_color (tuple(int)) – Color of texts. The tuple of color should be in BGR order. Default: (203, 192, 255), means 'pink'.

  • mask_color (tuple(int)) – Color of mask. The tuple of color should be in BGR order. Default: (128, 0, 128), means 'purple'.

  • thickness (int) – Thickness of lines. Default: 2.

  • font_size (int, float) – Font size of texts. Default: 0.8.

  • show (bool) – Whether to show the image. Default: True.

  • win_name (str) – The window name. Default: "win".

  • wait_time (int) – Waiting time delay for a key event in milliseconds. During image display, if there is no key pressed, wait for this time then jump to next image. If ESC is pressed, quit display immediately. If any other key is pressed, stop waiting then jump to next image directly. Default: 2000 , wait 2000ms then jump to next image.

  • out_file (str, optional) – The filename to write the imagee. Default: None. File extension name is required to indicate the image compression type, e.g. 'jpg', 'png'.

Returns

ndarray, The image with bboxes drawn on it.

Note

This interface relies on the opencv-python library.

Raises

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> from mindspore.dataset.utils import imshow_det_bbox
>>>
>>> # Read Detection dataset, such as VOC2012.
>>> voc_dataset_dir = "/path/to/voc_dataset_directory"
>>> dataset = ds.VOCDataset(voc_dataset_dir, task="Detection", shuffle=False, decode=True, num_samples=5)
>>> dataset_iter = dataset.create_dict_iterator(output_numpy=True, num_epochs=1)
>>>
>>> # draw dataset
>>> for index, data in enumerate(dataset_iter):
...     image = data["image"]
...     bbox = data["bbox"]
...     label = data["label"]
...     # draw image with bboxes
...     imshow_det_bbox(image, bbox, label,
...                     class_names=['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
...                                  'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
...                                  'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'],
...                     win_name="my_window",
...                     wait_time=5000,
...                     show=True,
...                     out_file="voc_dataset_{}.jpg".format(str(index)))

Examples using imshow_det_bbox on VOC2012:

../../_images/browse_dataset.png