快捷方式

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[原始碼]

在給定的 RGB 影像上繪製邊界框。影像值應為 uint8 型別,範圍 [0, 255];或 float 型別,範圍 [0, 1]。如果 fill 為 True,結果 Tensor 應儲存為 PNG 影像。

引數:
  • image (Tensor) – 形狀為 (C, H, W) 且資料型別為 uint8 或 float 的 Tensor。

  • boxes (Tensor) – 形狀為 (N, 4) 的 Tensor,包含 (xmin, ymin, xmax, ymax) 格式的邊界框。請注意,邊界框是相對於影像的絕對座標。換句話說:0 <= xmin < xmax < W0 <= ymin < ymax < H

  • labels (List[str]) – 包含邊界框標籤的列表。

  • colors (顏色顏色列表, 可選) – 包含框顏色的列表或所有框的單一顏色。顏色可以表示為 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 (顏色顏色列表, 可選) – 標籤文字的顏色。詳情請參閱 colors 引數的描述。預設為用於框的顏色。

返回:

繪製有邊界框的 uint8 資料型別的影像 Tensor。

返回型別:

img (Tensor[C, H, W])

使用 draw_bounding_boxes 的示例

將掩碼轉換為邊界框

將掩碼轉換為邊界框

視覺化工具函式

視覺化工具函式

文件

查閱全面的 PyTorch 開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源