Files
roboflow--supervision/README.md
T
wehub-resource-sync c6d676eb47
Pytest/Test Workflow / Build this Package (push) Failing after 13m39s
Check links & references / links-check (push) Has been cancelled
Docs/Test Workflow / Test docs build (push) Has been cancelled
PR Conflict Labeler / main (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / testing-guardian (push) Has been cancelled
docs: make Chinese README the default
2026-07-13 09:52:40 +00:00

12 KiB

Note

本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。

📑 目录

👋 你好

我们是你在计算机视觉(computer vision)领域的必备工具包。 从数据加载到实时区域计数,我们提供各类基础模块,让你可以专注于围绕模型构建应用。🤝

💻 安装

Python>=3.10 环境中,使用 pip 安装 supervision 包。

pip install supervision

如需了解 conda、mamba 及从源码安装的更多内容,请参阅我们的指南.

🔥 快速入门

模型

Supervision 在设计上是模型无关(model agnostic)的。你可以直接接入任意分类、检测或分割模型。为方便使用,我们为 Ultralytics、Transformers、MMDetection、Inference 等最流行的库创建了连接器。其他集成方式(如 rfdetr)已能直接返回 sv.Detections

使用 pip install pillow rfdetr 安装本示例所需的可选依赖。

import supervision as sv
from PIL import Image
from rfdetr import RFDETRSmall

image = Image.open("path/to/image.jpg")
model = RFDETRSmall()
detections = model.predict(image, threshold=0.5)

len(detections)
# 5
👉 更多模型连接器
  • inference

    使用 Inference 运行需要 Roboflow API KEY.

    import supervision as sv
    from PIL import Image
    from inference import get_model
    
    image = Image.open("path/to/image.jpg")
    model = get_model(model_id="rfdetr-small", api_key="ROBOFLOW_API_KEY")
    result = model.infer(image)[0]
    detections = sv.Detections.from_inference(result)
    
    len(detections)
    # 5
    

标注器

Supervision 提供大量高度可自定义的标注器,,可让你为具体场景组合出完美的可视化效果。

import cv2
import supervision as sv

image = cv2.imread("path/to/image.jpg")
# Assuming detections are obtained from a model
detections = sv.Detections(...)

box_annotator = sv.BoxAnnotator()
annotated_frame = box_annotator.annotate(scene=image.copy(), detections=detections)

https://github.com/roboflow/supervision/assets/26109316/691e219c-0565-4403-9218-ab5644f39bce

数据集

Supervision 提供一组工具函数,支持以支持的格式之一加载、拆分、合并和保存数据集。

import supervision as sv
from roboflow import Roboflow

project = Roboflow().workspace("WORKSPACE_ID").project("PROJECT_ID")
dataset = project.version("PROJECT_VERSION").download("coco")

ds = sv.DetectionDataset.from_coco(
    images_directory_path=f"{dataset.location}/train",
    annotations_path=f"{dataset.location}/train/_annotations.coco.json",
)

path, image, annotation = ds[0]
# loads image on demand

for path, image, annotation in ds:
    # loads image on demand
    pass
👉 更多数据集工具
  • load

    dataset = sv.DetectionDataset.from_yolo(
        images_directory_path=...,
        annotations_directory_path=...,
        data_yaml_path=...,
    )
    
    dataset = sv.DetectionDataset.from_pascal_voc(
        images_directory_path=...,
        annotations_directory_path=...,
    )
    
    dataset = sv.DetectionDataset.from_coco(
        images_directory_path=...,
        annotations_path=...,
    )
    
  • split

    train_dataset, test_dataset = dataset.split(split_ratio=0.7)
    test_dataset, valid_dataset = test_dataset.split(split_ratio=0.5)
    
    len(train_dataset), len(test_dataset), len(valid_dataset)
    # (700, 150, 150)
    
  • merge

    ds_1 = sv.DetectionDataset(...)
    len(ds_1)
    # 100
    ds_1.classes
    # ['dog', 'person']
    
    ds_2 = sv.DetectionDataset(...)
    len(ds_2)
    # 200
    ds_2.classes
    # ['cat']
    
    ds_merged = sv.DetectionDataset.merge([ds_1, ds_2])
    len(ds_merged)
    # 300
    ds_merged.classes
    # ['cat', 'dog', 'person']
    
  • save

    dataset.as_yolo(
        images_directory_path=...,
        annotations_directory_path=...,
        data_yaml_path=...,
    )
    
    dataset.as_pascal_voc(
        images_directory_path=...,
        annotations_directory_path=...,
    )
    
    dataset.as_coco(
        images_directory_path=...,
        annotations_path=...,
    )
    
  • convert

    sv.DetectionDataset.from_yolo(
        images_directory_path=...,
        annotations_directory_path=...,
        data_yaml_path=...,
    ).as_pascal_voc(
        images_directory_path=...,
        annotations_directory_path=...,
    )
    

🎬 教程

想了解如何使用 Supervision?可浏览我们的操作指南,、端到端示例速查表, 和 cookbook!


Dwell Time Analysis with Computer Vision | Real-Time Stream Processing Dwell Time Analysis with Computer Vision | Real-Time Stream Processing

创建时间:2024 年 4 月 5 日

了解如何使用计算机视觉分析等待时间并优化流程。本教程涵盖目标检测、跟踪,以及计算在指定区域内的停留时间。可将这些技术用于提升零售、交通管理等场景下的客户体验。


速度估算与车辆跟踪 | 计算机视觉 | 开源 速度估算与车辆跟踪 | 计算机视觉 | 开源

创建日期:2024 年 1 月 11 日

学习如何使用 YOLO、ByteTrack 和 Roboflow Inference 跟踪并估算车辆速度。本综合教程涵盖目标检测(object detection)、多目标跟踪(multi-object tracking)、检测结果过滤、透视变换(perspective transformation)、速度估算、可视化改进等内容。

💜 使用 Supervision 构建

你是否使用 supervision 构建了很酷的项目?告诉我们!

https://user-images.githubusercontent.com/26109316/207858600-ee862b22-0353-440b-ad85-caa0c4777904.mp4

https://github.com/roboflow/supervision/assets/26109316/c9436828-9fbf-4c25-ae8c-60e9c81b3900

https://github.com/roboflow/supervision/assets/26109316/3ac6982f-4943-4108-9b7f-51787ef1a69f

📚 文档

访问我们的文档 页面,了解 supervision 如何帮助你更快、更可靠地构建计算机视觉应用。

🏆 贡献

我们欢迎你的反馈!请查阅我们的贡献指南开始参与。感谢 🙏 所有贡献者!