Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

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