draw_bounding_boxes¶
- torchvision.utils.draw_bounding_boxes(image: Tensor, boxes: Tensor, labels: Optional[List[str]] = None, colors: Optional[Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]] = None, fill: Optional[bool] = False, width: int = 1, font: Optional[str] = None, font_size: Optional[int] = None, label_colors: Optional[Union[List[Union[str, Tuple[int, int, int]]], str, Tuple[int, int, int]]] = None) Tensor [source]¶
在給定的 RGB 影像上繪製邊界框。影像數值應為 uint8 [0, 255] 或 float [0, 1]。如果 fill 為 True,則產生的 Tensor 應儲存為 PNG 影像。
- 參數:
image (Tensor) – 形狀為 (C, H, W) 且 dtype 為 uint8 或 float 的 Tensor。
boxes (Tensor) – 大小為 (N, 4) 的 Tensor,包含 (xmin, ymin, xmax, ymax) 格式的邊界框。請注意,這些框是相對於影像的絕對座標。換句話說: 0 <= xmin < xmax < W 且 0 <= ymin < ymax < H。
labels (List[str]) – 包含邊界框標籤的清單。
colors (color 或 顏色清單, optional) – 包含框顏色的清單,或所有框的單一顏色。顏色可以表示為 PIL 字串,例如“red”或“#FF00FF”,或表示為 RGB 元組,例如
(240, 10, 157)
。預設情況下,會為框產生隨機顏色。fill (bool) – 如果 True,則以指定的顏色填充邊界框。
width (int) – 邊界框的寬度。
font (str) – 包含 TrueType 字型的檔案名稱。 如果在此檔案名稱中找不到該檔案,載入器也可能會在其他目錄中搜尋,例如 Windows 上的 fonts/ 目錄,或 macOS 上的 /Library/Fonts/、 /System/Library/Fonts/ 和 ~/Library/Fonts/。
font_size (int) – 以點為單位要求的字型大小。
label_colors (color 或 顏色清單, optional) – 標籤文字的顏色。 請參閱 colors 參數的描述以了解詳細資訊。 預設為用於框的相同顏色。
- 回傳:
dtype 為 uint8 且繪製了邊界框的影像 Tensor。
- 回傳類型:
img (Tensor[C, H, W])
使用
draw_bounding_boxes
的範例