@@ -17,6 +17,15 @@ comments: true
We write your reusable computer vision tools. Whether you need to load your dataset from your hard drive, draw detections on an image or video, or count how many detections are in a zone. You can count on us!
+
+
+## 🚀 Quickstart
+
- __Detect and Annotate__
diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py
index 5b206e35..2b2ca6ba 100644
--- a/supervision/annotators/core.py
+++ b/supervision/annotators/core.py
@@ -146,9 +146,6 @@ class OrientedBoxAnnotator(BaseAnnotator):
... detections=detections
... )
```
-
- 
""" # noqa E501 // docs
if detections.data is None or "xyxyxyxy" not in detections.data:
diff --git a/supervision/detection/core.py b/supervision/detection/core.py
index 44575253..b9914b99 100644
--- a/supervision/detection/core.py
+++ b/supervision/detection/core.py
@@ -130,7 +130,7 @@ class Detections:
import torch
import supervision as sv
- image = cv2.imread(SOURCE_IMAGE_PATH)
+ image = cv2.imread()
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
result = model(image)
detections = sv.Detections.from_yolov5(result)
@@ -150,6 +150,13 @@ class Detections:
Creates a Detections instance from a
[YOLOv8](https://github.com/ultralytics/ultralytics) inference result.
+ !!! Note
+
+ `from_ultralytics` is compatible with
+ [detection](https://docs.ultralytics.com/tasks/detect/),
+ [segmentation](https://docs.ultralytics.com/tasks/segment/), and
+ [OBB](https://docs.ultralytics.com/tasks/obb/) models.
+
Args:
ultralytics_results (ultralytics.yolo.engine.results.Results):
The output Results instance from YOLOv8
@@ -163,12 +170,13 @@ class Detections:
import supervision as sv
from ultralytics import YOLO
- image = cv2.imread()
+ image = cv2.imread()
model = YOLO('yolov8s.pt')
+
result = model(image)[0]
detections = sv.Detections.from_ultralytics(result)
```
- """
+ """ # noqa: E501 // docs
if ultralytics_results.obb is not None:
return cls(
@@ -213,8 +221,9 @@ class Detections:
from super_gradients.training import models
import supervision as sv
- image = cv2.imread(SOURCE_IMAGE_PATH)
+ image = cv2.imread()
model = models.get('yolo_nas_l', pretrained_weights="coco")
+
result = list(model.predict(image, conf=0.35))[0]
detections = sv.Detections.from_yolo_nas(result)
```
@@ -309,9 +318,9 @@ class Detections:
@classmethod
def from_mmdetection(cls, mmdet_results) -> Detections:
"""
- Creates a Detections instance from
- a [mmdetection](https://github.com/open-mmlab/mmdetection) inference result.
- Also supported for [mmyolo](https://github.com/open-mmlab/mmyolo)
+ Creates a Detections instance from a
+ [mmdetection](https://github.com/open-mmlab/mmdetection) and
+ [mmyolo](https://github.com/open-mmlab/mmyolo) inference result.
Args:
mmdet_results (mmdet.structures.DetDataSample):
@@ -324,14 +333,15 @@ class Detections:
```python
import cv2
import supervision as sv
- from mmdet.apis import DetInferencer
+ from mmdet.apis import init_detector, inference_detector
+
+ image = cv2.imread()
+ model = init_detector(, , device=)
- inferencer = DetInferencer(model_name, checkpoint, device)
- mmdet_result = inferencer(SOURCE_IMAGE_PATH, out_dir='./output',
- return_datasamples=True)["predictions"][0]
- detections = sv.Detections.from_mmdetection(mmdet_result)
+ result = inference_detector(model, image)
+ detections = sv.Detections.from_mmdetection(result)
```
- """
+ """ # noqa: E501 // docs
return cls(
xyxy=mmdet_results.pred_instances.bboxes.cpu().numpy(),
@@ -372,15 +382,17 @@ class Detections:
Example:
```python
import cv2
+ import supervision as sv
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
- import supervision as sv
- image = cv2.imread(SOURCE_IMAGE_PATH)
+
+ image = cv2.imread()
cfg = get_cfg()
- cfg.merge_from_file("path/to/config.yaml")
- cfg.MODEL.WEIGHTS = "path/to/model_weights.pth"
+ cfg.merge_from_file()
+ cfg.MODEL.WEIGHTS =
predictor = DefaultPredictor(cfg)
+
result = predictor(image)
detections = sv.Detections.from_detectron2(result)
```
@@ -423,8 +435,9 @@ class Detections:
import supervision as sv
from inference.models.utils import get_roboflow_model
- image = cv2.imread()
+ image = cv2.imread()
model = get_roboflow_model(model_id="yolov8s-640")
+
result = model.infer(image)[0]
detections = sv.Detections.from_inference(result)
```
@@ -472,8 +485,9 @@ class Detections:
import supervision as sv
from inference.models.utils import get_roboflow_model
- image = cv2.imread()
+ image = cv2.imread()
model = get_roboflow_model(model_id="yolov8s-640")
+
result = model.infer(image)[0]
detections = sv.Detections.from_roboflow(result)
```
@@ -888,13 +902,12 @@ class Detections:
Example:
```python
import cv2
- from ultralytics import YOLO
import supervision as sv
+ from ultralytics import YOLO
+ image = cv2.imread()
model = YOLO('yolov8s.pt')
- image = cv2.imread(SOURCE_IMAGE_PATH)
-
result = model(image)[0]
detections = sv.Detections.from_ultralytics(result)
@@ -950,7 +963,8 @@ class Detections:
Args:
threshold (float, optional): The intersection-over-union threshold
- to use for non-maximum suppression. Defaults to 0.5.
+ to use for non-maximum suppression. I'm the lower the value the more
+ restrictive the NMS becomes. Defaults to 0.5.
class_agnostic (bool, optional): Whether to perform class-agnostic
non-maximum suppression. If True, the class_id of each detection
will be ignored. Defaults to False.
diff --git a/supervision/tracker/byte_tracker/core.py b/supervision/tracker/byte_tracker/core.py
index bf831daa..8b74aa02 100644
--- a/supervision/tracker/byte_tracker/core.py
+++ b/supervision/tracker/byte_tracker/core.py
@@ -166,6 +166,10 @@ def detections2boxes(detections: Detections) -> np.ndarray:
class ByteTrack:
"""
Initialize the ByteTrack object.
+
+
Parameters:
track_thresh (float, optional): Detection confidence threshold
@@ -173,7 +177,7 @@ class ByteTrack:
track_buffer (int, optional): Number of frames to buffer when a track is lost.
match_thresh (float, optional): Threshold for matching tracks with detections.
frame_rate (int, optional): The frame rate of the video.
- """
+ """ # noqa: E501 // docs
def __init__(
self,
@@ -196,36 +200,39 @@ class ByteTrack:
def update_with_detections(self, detections: Detections) -> Detections:
"""
- Updates the tracker with the provided detections and
- returns the updated detection results.
+ Updates the tracker with the provided detections and returns the updated
+ detection results.
+
+ Args:
+ detections (Detections): The detections to pass through the tracker.
- Parameters:
- detections: The new detections to update with.
- Returns:
- Detection: The updated detection results that now include tracking IDs.
Example:
```python
import supervision as sv
from ultralytics import YOLO
- model = YOLO(...)
- byte_tracker = sv.ByteTrack()
- annotator = sv.BoxAnnotator()
+ model = YOLO()
+ tracker = sv.ByteTrack()
+
+ bounding_box_annotator = sv.BoundingBoxAnnotator()
+ label_annotator = sv.LabelAnnotator()
def callback(frame: np.ndarray, index: int) -> np.ndarray:
results = model(frame)[0]
detections = sv.Detections.from_ultralytics(results)
detections = byte_tracker.update_with_detections(detections)
- labels = [
- f"#{tracker_id} {model.model.names[class_id]} {confidence:0.2f}"
- for _, _, confidence, class_id, tracker_id in detections
- ]
- return annotator.annotate(scene=frame.copy(),
- detections=detections, labels=labels)
+
+ labels = [f"#{tracker_id}" for tracker_id in detections.tracker_id]
+
+ annotated_frame = bounding_box_annotator.annotate(
+ scene=frame.copy(), detections=detections)
+ annotated_frame = label_annotator.annotate(
+ scene=annotated_frame, detections=detections, labels=labels)
+ return annotated_frame
sv.process_video(
- source_path='...',
- target_path='...',
+ source_path=,
+ target_path=,
callback=callback
)
```