> [!NOTE]
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
> [English](./README.en.md) · [原始项目](https://github.com/roboflow/supervision) · [上游 README](https://github.com/roboflow/supervision/blob/HEAD/README.md)
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
[notebooks](https://github.com/roboflow/notebooks) | [inference](https://github.com/roboflow/inference) | [autodistill](https://github.com/autodistill/autodistill) | [maestro](https://github.com/roboflow/multimodal-maestro)
[](https://badge.fury.io/py/supervision) [](https://pypistats.org/packages/supervision) [](LICENSE.md) [](https://badge.fury.io/py/supervision) [](https://codecov.io/gh/roboflow/supervision)
[](https://snyk.io/advisor/python/supervision) [](https://colab.research.google.com/github/roboflow/supervision/blob/main/demo.ipynb) [](https://huggingface.co/spaces/Roboflow/Annotators) [](https://discord.gg/GbfgXGJ8Bk)
📑 目录
- [👋 你好](#-hello)
- [💻 安装](#-install)
- [🔥 快速入门](#-quickstart)
- [模型](#models)
- [标注器](#annotators)
- [数据集](#datasets)
- [🎬 教程](#-tutorials)
- [💜 使用 Supervision 构建](#-built-with-supervision)
- [📚 文档](#-documentation)
- [🏆 贡献](#-contribution)
## 👋 你好
**我们是你在计算机视觉(computer vision)领域的必备工具包。** 从数据加载到实时区域计数,我们提供各类基础模块,让你可以专注于围绕模型构建应用。🤝
## 💻 安装
在 [**Python>=3.10**](https://www.python.org/) 环境中,使用 pip 安装 supervision 包。
```bash
pip install supervision
```
如需了解 conda、mamba 及从源码安装的更多内容,请参阅我们的[指南](https://roboflow.github.io/supervision/).
## 🔥 快速入门
### 模型
Supervision 在设计上是模型无关(model agnostic)的。你可以直接接入任意分类、检测或分割模型。为方便使用,我们为 Ultralytics、Transformers、MMDetection、Inference 等最流行的库创建了[连接器](https://supervision.roboflow.com/latest/detection/core/#detections)。其他集成方式(如 `rfdetr`)已能直接返回 `sv.Detections`。
使用 `pip install pillow rfdetr` 安装本示例所需的可选依赖。
```python
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](https://github.com/roboflow/inference) 运行需要 [Roboflow API KEY](https://docs.roboflow.com/api-reference/authentication#retrieve-an-api-key).
```python
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 提供大量高度可自定义的[标注器](https://supervision.roboflow.com/latest/detection/annotators/),,可让你为具体场景组合出完美的可视化效果。
```python
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 提供一组[工具函数](https://supervision.roboflow.com/latest/datasets/core/),支持以支持的格式之一加载、拆分、合并和保存数据集。
```python
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
```python
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
```python
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
```python
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
```python
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
```python
sv.DetectionDataset.from_yolo(
images_directory_path=...,
annotations_directory_path=...,
data_yaml_path=...,
).as_pascal_voc(
images_directory_path=...,
annotations_directory_path=...,
)
```
## 🎬 教程
想了解如何使用 Supervision?可浏览我们的[操作指南](https://supervision.roboflow.com/develop/how_to/detect_and_annotate/),、[端到端示例](./examples)、[速查表](https://roboflow.github.io/cheatsheet-supervision/), 和 [cookbook](https://supervision.roboflow.com/develop/cookbooks/)!
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://github.com/roboflow/supervision/discussions/categories/built-with-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
## 📚 文档
访问我们的[文档](https://roboflow.github.io/supervision) 页面,了解 supervision 如何帮助你更快、更可靠地构建计算机视觉应用。
## 🏆 贡献
我们欢迎你的反馈!请查阅我们的[贡献指南](.github/CONTRIBUTING.md)开始参与。感谢 🙏 所有贡献者!