### Install with uv (pip) Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Use uv to install the supervision library. This command is for general pip-style installations. ```bash uv pip install supervision ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/serialise-detections-to-csv.ipynb Installs necessary libraries for the cookbook. Use this to set up your environment. ```bash !pip install -q inference requests tqdm supervision ``` -------------------------------- ### Download Sample Video Assets Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/track_objects.md Downloads the 'PEOPLE_WALKING' video asset for use in examples. Ensure the supervision library is installed. ```python from supervision.assets import download_assets, VideoAssets download_assets(VideoAssets.PEOPLE_WALKING) ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/object-tracking.ipynb Install the necessary libraries, including inference-gpu and supervision, for object tracking. The '-q' flag ensures quiet installation. ```bash !pip install -q inference-gpu "supervision" ``` -------------------------------- ### Install with pip Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Use pip to install the supervision library. This is the recommended method for most users. ```bash pip install supervision ``` -------------------------------- ### Download Example Video Assets Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/track_objects.md Downloads the 'SKIING' video asset for use in examples. Ensure the supervision library is installed with asset support. ```python from supervision.assets import download_assets, VideoAssets download_assets(VideoAssets.SKIING) ``` -------------------------------- ### Clone Repository and Navigate to Example Directory Source: https://github.com/roboflow/supervision/blob/develop/examples/heatmap_and_track/README.md Clone the supervision repository and change the directory to the heatmap_and_track example. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/heatmap_and_track ``` -------------------------------- ### Install supervision Source: https://github.com/roboflow/supervision/blob/develop/docs/llms-100k.txt Install the supervision library using pip. Optional extras for metrics can be installed with `[metrics]`. ```bash pip install supervision ``` ```bash pip install "supervision[metrics]" ``` -------------------------------- ### Install Supervision Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/download-supervision-assets.ipynb Install the supervision package using pip. The `-q` flag ensures quiet installation. ```python pip install -q "supervision" ``` -------------------------------- ### Clone Repository and Navigate to Example Directory Source: https://github.com/roboflow/supervision/blob/develop/examples/time_in_zone/README.md Clone the Supervision repository and navigate to the time_in_zone example directory. This is the first step to set up the project. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/time_in_zone ``` -------------------------------- ### Install and Import Supervision Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Installs the supervision library using pip and imports it for use in the notebook. The installed version is then printed. ```python !pip install -q supervision import supervision as sv print(sv.__version__) ``` -------------------------------- ### Development Install with uv Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Clone the repository and set up a development environment using uv. ```bash # clone repository and navigate to root directory git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision # setup python environment and activate it uv venv source .venv/bin/activate # installation uv pip install -r pyproject.toml -e . --all-extras ``` -------------------------------- ### Run Ultralytics Example Source: https://github.com/roboflow/supervision/blob/develop/examples/tracking/README.md Execute the Ultralytics example script, providing the path to YOLOv8 weights, source video, and target video. ```bash python ultralytics_example.py \ --source_weights_path yolov8s.pt \ --source_video_path input.mp4 \ --target_video_path tracking_result.mp4 ``` -------------------------------- ### Clone Repository and Navigate to Example Directory Source: https://github.com/roboflow/supervision/blob/develop/examples/tracking/README.md Use these bash commands to clone the supervision repository and navigate to the tracking examples directory. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/tracking ``` -------------------------------- ### Install Required Packages Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/count-objects-crossing-the-line.ipynb Install the ultralytics and supervision packages for object detection and tracking. This command installs them quietly. ```bash !pip install -q ultralytics supervision ``` -------------------------------- ### Install Supervision and Dependencies Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/compact-mask-sam3.ipynb Installs supervision version 0.28.0 along with rfdetr, inference-sdk, numpy, and matplotlib. Use this to set up the environment for the examples. ```python !pip install -q 'supervision==0.28.0' 'rfdetr' 'inference-sdk>=0.9' numpy matplotlib ``` -------------------------------- ### Install Supervision Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Install the supervision package using pip. For YOLOv8 integration, also install ultralytics. ```bash pip install supervision ultralytics ``` -------------------------------- ### Install with Conda Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Install supervision using Conda from the conda-forge channel. ```bash conda install -c conda-forge supervision ``` -------------------------------- ### Download Example Files Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb Download a sample image (dog.jpeg) and a video (yellow-filling.mp4) to use as input for the object detection model. These files will be saved in the HOME directory. ```bash !wget -P {HOME} -q https://media.roboflow.com/notebooks/examples/dog.jpeg !wget -P {HOME} -q https://media.roboflow.com/supervision/cookbooks/yellow-filling.mp4 ``` -------------------------------- ### Download Example Images Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Navigates to the 'images' directory and downloads several example JPEG images using wget. These images are used for demonstration purposes. ```bash %cd {HOME}/images !wget -q https://media.roboflow.com/notebooks/examples/dog.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-2.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-3.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-4.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-5.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-6.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-7.jpeg !wget -q https://media.roboflow.com/notebooks/examples/dog-8.jpeg ``` -------------------------------- ### Run Ultralytics Example Source: https://github.com/roboflow/supervision/blob/develop/examples/count_people_in_zone/README.md Execute the ultralytics example script to perform object detection and zone counting. Specify paths for zone configuration and source video, along with confidence and IOU thresholds. ```bash python ultralytics_example.py \ --zone_configuration_path data/multi-zone-config.json \ --source_video_path data/market-square.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 ``` -------------------------------- ### Install Roboflow and Inference Libraries Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/benchmark_a_model.md Install the roboflow and inference libraries. The inference library is installed from a specific GitHub branch. ```bash pip install roboflow supervision pip install git+https://github.com/roboflow/inference.git@linas/allow-latest-rc-supervision ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/roboflow/supervision/blob/develop/examples/speed_estimation/README.md Clone the supervision repository and navigate to the speed estimation example directory. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/speed_estimation ``` -------------------------------- ### Install Supervision with Assets Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Installs the supervision library with optional assets, which may include sample videos for demonstration purposes. This is a prerequisite for using certain video-related utilities. ```python !pip install -q supervision[assets] ``` -------------------------------- ### Install Roboflow and Supervision Packages Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/occupancy_analytics.ipynb Installs the Roboflow package for model training and the Supervision package for data visualization and metric extraction. The '-q' flag ensures a quiet installation. ```python !pip install roboflow supervision -q ``` -------------------------------- ### Run Ultralytics Example Source: https://github.com/roboflow/supervision/blob/develop/examples/traffic_analysis/README.md Execute the ultralytics example script for traffic analysis. This command specifies paths for weights, source video, confidence and IOU thresholds, and the output video. ```bash python ultralytics_example.py \ --source_weights_path data/traffic_analysis.pt \ --source_video_path data/traffic_analysis.mov \ --confidence_threshold 0.3 \ --iou_threshold 0.5 \ --target_video_path data/traffic_analysis_result.mov ``` -------------------------------- ### Install Supervision Source: https://github.com/roboflow/supervision/blob/develop/docs/llms.full.txt Install the supervision library using pip. For optional metric dependencies, include the 'metrics' extra. ```bash pip install supervision ``` ```bash pip install supervision[metrics] ``` -------------------------------- ### Install Albumentations Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/process_datasets.md Install the Albumentations library using pip. This is a prerequisite for using its augmentation capabilities. ```bash pip install albumentations ``` -------------------------------- ### Development Install with virtualenv Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Clone the repository and set up a development environment using virtualenv and pip. ```bash # clone repository and navigate to root directory git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision # setup python environment and activate it python3 -m venv venv source venv/bin/activate pip install --upgrade pip # installation pip install -e "." ``` -------------------------------- ### Install Inference Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Install the inference package for model deployment. ```bash pip install inference ``` -------------------------------- ### Setup Python Environment Source: https://github.com/roboflow/supervision/blob/develop/examples/heatmap_and_track/README.md Set up a Python virtual environment using 'uv' and activate it. This is an optional step for managing dependencies. ```bash uv venv source .venv/bin/activate ``` -------------------------------- ### Install Supervision Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Installs the supervision package quietly. Use this to ensure the library is available for use. ```bash !pip install -q supervision ``` -------------------------------- ### Run Ultralytics Example Source: https://github.com/roboflow/supervision/blob/develop/examples/speed_estimation/README.md Execute the Ultralytics speed estimation script with specified video paths and thresholds. ```bash python ultralytics_example.py \ --source_video_path data/vehicles.mp4 \ --target_video_path data/vehicles-result.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 ``` -------------------------------- ### Install Required Dependencies Source: https://github.com/roboflow/supervision/blob/develop/examples/heatmap_and_track/README.md Install all necessary Python dependencies listed in the requirements.txt file using 'uv pip'. ```bash uv pip install -r requirements.txt ``` -------------------------------- ### Install SuperGradients Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Installs the super-gradients library, which is required for using YOLO-NAS models. ```bash !pip install -q super-gradients ``` -------------------------------- ### Download Example Video Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/count-objects-crossing-the-line.ipynb Download a sample video asset (VEHICLES) using supervision.assets. This video will be used for demonstration. ```python download_assets(VideoAssets.VEHICLES) ``` -------------------------------- ### Run YOLO-NAS Example Source: https://github.com/roboflow/supervision/blob/develop/examples/speed_estimation/README.md Execute the YOLO-NAS speed estimation script with specified video paths and thresholds. ```bash python yolo_nas_example.py \ --source_video_path data/vehicles.mp4 \ --target_video_path data/vehicles-result.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 ``` -------------------------------- ### Install Roboflow Package Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Install the `roboflow` pip package quietly using `pip install -q roboflow`. This is a prerequisite for downloading datasets from Roboflow Universe. ```python !pip install -q roboflow ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/roboflow/supervision/blob/develop/examples/traffic_analysis/README.md Clone the supervision repository and navigate to the traffic_analysis example directory. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/traffic_analysis ``` -------------------------------- ### Run Inference Example Source: https://github.com/roboflow/supervision/blob/develop/examples/count_people_in_zone/README.md Execute the inference example script using a Roboflow API key. Specify paths for zone configuration and source video, along with confidence and IOU thresholds. ```bash python inference_example.py \ --roboflow_api_key "ROBOFLOW_API_KEY" \ --zone_configuration_path data/multi-zone-config.json \ --source_video_path data/market-square.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 ``` -------------------------------- ### Download Model and Video Source: https://github.com/roboflow/supervision/blob/develop/examples/count_people_in_zone/README.md Download the necessary model weights (traffic_analysis.pt) and video file (traffic_analysis.mov) using the provided setup script. ```bash ./setup.sh ``` -------------------------------- ### Install Supervision with Metrics Extra Source: https://github.com/roboflow/supervision/blob/develop/docs/faq.md Install Supervision with the optional 'metrics' extra dependencies. This is required for using advanced metric calculation features. ```bash pip install "supervision[metrics]" ``` -------------------------------- ### Install with Poetry Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Use Poetry to add supervision as a dependency to your project. ```bash poetry add supervision ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/roboflow/supervision/blob/develop/examples/count_people_in_zone/README.md Clone the supervision repository and navigate to the specific example directory for the count_people_in_zone demo. ```bash git clone --depth 1 -b develop https://github.com/roboflow/supervision.git cd supervision/examples/count_people_in_zone ``` -------------------------------- ### Install Roboflow Package Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/process_datasets.md Install the Roboflow package to interact with Roboflow datasets. This is a prerequisite for downloading datasets. ```bash pip install roboflow ``` -------------------------------- ### Install Supervision and Ultralytics Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/oriented-bounding-boxes.ipynb Install the required packages for using supervision and ultralytics for object detection. Ensure supervision is version 0.29.0 or newer. ```python %pip install -q "supervision>=0.29.0" ultralytics ``` -------------------------------- ### Start and Join Inference Pipeline Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/serialise-detections-to-csv.ipynb Starts the video processing pipeline and waits for it to complete. ```python pipeline.start() pipeline.join() ``` -------------------------------- ### Install Supervision Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb Install the supervision package for post-processing and visualizing detection results. This is a key dependency for working with detection outputs. ```bash !pip install -q supervision==0.19.0rc3 ``` -------------------------------- ### Install with Mamba Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Install supervision using Mamba from the conda-forge channel. Mamba is a faster alternative to Conda. ```bash mamba install -c conda-forge supervision ``` -------------------------------- ### Run Inference Example Source: https://github.com/roboflow/supervision/blob/develop/examples/traffic_analysis/README.md Execute the inference example script for traffic analysis. This command requires a Roboflow API key and specifies paths for the source video, confidence and IOU thresholds, and the output video. ```bash python inference_example.py \ --roboflow_api_key "ROBOFLOW_API_KEY" \ --source_video_path data/traffic_analysis.mov \ --confidence_threshold 0.3 \ --iou_threshold 0.5 \ --target_video_path data/traffic_analysis_result.mov ``` -------------------------------- ### Install Required Packages Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/small-object-detection-with-sahi.ipynb Installs the necessary Python packages for the project, including inference, supervision, and jupyter_compare_view. ```python %pip install inference supervision jupyter_compare_view ``` -------------------------------- ### Install Super-Gradients and Update Urllib3 Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Installs the super-gradients package and upgrades urllib3. These are prerequisites for using YOLO-NAS models. ```bash !pip install -q super-gradients !pip install --upgrade urllib3 ``` -------------------------------- ### Install Supervision Base Package Source: https://github.com/roboflow/supervision/blob/develop/docs/faq.md Install the core Supervision package using pip. This includes essential utilities for computer vision workflows. ```bash pip install supervision ``` -------------------------------- ### Initialize VideoInfo Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Initialize VideoInfo to get metadata about a video file. ```python from supervision.video.core import VideoInfo video_info = VideoInfo.from_video_path(video_path='your_video.mp4') ``` -------------------------------- ### Install Inference GPU Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb Install the inference-gpu package with YOLO-World support. This package is required for running zero-shot object detection. ```bash !pip install -q inference-gpu[yolo-world]==0.9.12rc1 ``` -------------------------------- ### Install Required Python Packages Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/evaluating-alignment-of-text-to-image-diffusion-models.ipynb Install necessary libraries including PyTorch, diffusers, accelerate, inference-gpu, and supervision. This command ensures all dependencies for image generation and analysis are met. ```bash !pip install -q torch diffusers accelerate inference-gpu[yolo-world] dill git+https://github.com/openai/CLIP.git supervision ``` -------------------------------- ### Install and Load Ultralytics YOLO Model Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/benchmark_a_model.md Install the Ultralytics library and load a YOLO model checkpoint for use with Supervision. Ensure you are using a compatible version of the `ultralytics` package. ```bash pip install "ultralytics<=8.3.40" ``` ```python from ultralytics import YOLO model = YOLO("yolo11s-seg.pt") ``` -------------------------------- ### Run Inference Example Source: https://github.com/roboflow/supervision/blob/develop/examples/tracking/README.md Execute the inference script with specified Roboflow API key, source video, and target video paths. ```bash python inference_example.py \ --roboflow_api_key "ROBOFLOW_API_KEY" \ --source_video_path input.mp4 \ --target_video_path tracking_result.mp4 ``` -------------------------------- ### Create Images Directory Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Creates a directory named 'images' within the current working directory to store example images. This is a prerequisite for downloading sample data. ```bash !mkdir {HOME}/images ``` -------------------------------- ### Download Video Source: https://github.com/roboflow/supervision/blob/develop/examples/speed_estimation/README.md Download the 'vehicles.mp4' video file required for the speed estimation examples. ```bash python video_downloader.py ``` -------------------------------- ### Run Inference Example Source: https://github.com/roboflow/supervision/blob/develop/examples/speed_estimation/README.md Execute the inference speed estimation script, requiring a Roboflow API key and specifying video paths and thresholds. ```bash python inference_example.py \ --roboflow_api_key "ROBOFLOW_API_KEY" \ --source_video_path data/vehicles.mp4 \ --target_video_path data/vehicles-result.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 ``` -------------------------------- ### Import Libraries and Print Version Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/oriented-bounding-boxes.ipynb Import necessary libraries including cv2, numpy, os, supervision, and YOLO. Print the installed supervision version to verify. ```python import cv2 import numpy as np import os import supervision as sv from ultralytics import YOLO print(sv.__version__) ``` -------------------------------- ### Download Sample Image Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/detect_and_annotate.md Use wget to download the sample image used in this tutorial. Replace `` with "dog.jpeg" after downloading. ```bash wget https://media.roboflow.com/notebooks/examples/dog.jpeg ``` -------------------------------- ### Annotate Image with Segmentation Masks (Ultralytics) Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/detect_and_annotate.md This example demonstrates how to annotate an image with segmentation masks and labels when using the Ultralytics YOLO framework. Make sure you have `ultralytics` and `supervision` installed. ```python import cv2 import supervision as sv from ultralytics import YOLO model = YOLO("yolov8n-seg.pt") image = cv2.imread("dog.jpeg") results = model(image)[0] detections = sv.Detections.from_ultralytics(results) mask_annotator = sv.MaskAnnotator() label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER_OF_MASS) annotated_image = mask_annotator.annotate( scene=image, detections=detections, ) annotated_image = label_annotator.annotate( scene=annotated_image, detections=detections, ) ``` -------------------------------- ### Annotate Image with Segmentation Masks (Inference) Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/detect_and_annotate.md Use this snippet to annotate an image with segmentation masks and labels when using a custom inference setup. Ensure you have the `inference` library installed and the model loaded. ```python import cv2 import supervision as sv from inference import get_model model = get_model(model_id="yolov8n-seg-640") image = cv2.imread("dog.jpeg") results = model.infer(image)[0] detections = sv.Detections.from_inference(results) mask_annotator = sv.MaskAnnotator() label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER_OF_MASS) annotated_image = mask_annotator.annotate( scene=image, detections=detections, ) annotated_image = label_annotator.annotate( scene=annotated_image, detections=detections, ) sv.plot_image(annotated_image) ``` -------------------------------- ### Install Ultralytics YOLO Source: https://github.com/roboflow/supervision/blob/develop/demo.ipynb Installs the ultralytics library, required for using YOLOv8 models. ```bash !pip install -q "ultralytics<=8.3.40" ``` -------------------------------- ### Define Configuration Parameters Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/serialise-detections-to-csv.ipynb Sets up configuration variables for video source, confidence thresholds, output file name, and inference model. ```python SOURCE_VIDEO_PATH = download_assets(VideoAssets.PEOPLE_WALKING) CONFIDENCE_THRESHOLD = 0.3 IOU_THRESHOLD = 0.7 FILE_NAME = "detections.csv" INFERENCE_MODEL = "yolov8n-640" ``` -------------------------------- ### Install Inference Package Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Installs the inference package quietly. This is used for integrating models from the inference library. ```bash !pip install -q inference ``` -------------------------------- ### Initialize Object Tracking Components Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/object-tracking.ipynb Load a pre-trained model, set up video information, create a label annotator, initialize a ByteTrack tracker, and prepare a frame generator for processing video frames. ```python import supervision as sv from inference.models.utils import get_roboflow_model # Load a pre trained yolov8 nano model from Roboflow Inference. model = get_roboflow_model('yolov8n-640') # Create a video info object from the video path. video_info = sv.VideoInfo.from_video_path(path_to_video) # Create a label annotator for labeling detections with our tracker_id. label = sv.LabelAnnotator() # Create a ByteTrack object to track detections. byte_tracker = sv.ByteTrack(frame_rate=video_info.fps) # Create a frame generator from video path for iteration of frames. frame_generator = sv.get_video_frames_generator(path_to_video) ``` -------------------------------- ### Initialize YOLO Model and Load Video Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/count_in_zone.md Set up a YOLO model for object detection and load a video file using supervision's VideoInfo. This prepares the environment for frame-by-frame inference and metadata extraction. ```python import numpy as np import supervision as sv import cv2 from ultralytics import YOLO model = YOLO("yolov8s.pt") VIDEO = str(VideoAssets.VEHICLES_2) colors = sv.ColorPalette.default() video_info = sv.VideoInfo.from_video_path(VIDEO) ``` -------------------------------- ### Initialize Supervision Tools Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/occupancy_analytics.ipynb Initialize various Supervision tools including ByteTrack for tracking, InferenceSlicer for processing frames, TriangleAnnotator for visualization, and PolygonZone/PolygonZoneAnnotator for zone-based analysis. ```python tracker = sv.ByteTrack() slicer = sv.InferenceSlicer( callback=callback, slice_wh=(800, 800), overlap_ratio_wh=(0.2, 0.2), thread_workers=10, iou_threshold=0.2 ) triangle_annotator = sv.TriangleAnnotator( base=20, height=20 ) heat_map_annotator = sv.HeatMapAnnotator() ``` -------------------------------- ### Run Heatmap and Tracking Script Source: https://github.com/roboflow/supervision/blob/develop/examples/heatmap_and_track/README.md Execute the main script with specified arguments for object detection and tracking. Ensure 'weight.pt' and 'input_video.mp4' are valid paths. ```bash python script.py \ --source_weights_path weight.pt \ --source_video_path input_video.mp4 \ --confidence_threshold 0.3 \ --iou_threshold 0.5 \ --target_video_path output_video.mp4 ``` -------------------------------- ### Download and Display Sample Image Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/compact-mask-sam3.ipynb Downloads a sample image using `sv.ImageAssets` and displays it using matplotlib. This code sets up the image for subsequent processing steps. ```python %matplotlib inline import cv2 import matplotlib.pyplot as plt import numpy as np import supervision as sv from supervision.assets import ImageAssets, download_assets image_path = download_assets(ImageAssets.PEOPLE_WALKING) print(f"Image: {image_path}") image_bgr = cv2.imread(image_path) image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB) H, W = image_bgr.shape[:2] print(f"Resolution: {W} x {H}") plt.figure(figsize=(12, 7)) plt.imshow(image_rgb) plt.axis("off") plt.title("people-walking.jpg") plt.tight_layout() plt.show() ``` -------------------------------- ### Get Detection Areas Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb After inferring detections from a frame, access the `area` property of the `sv.Detections` object to get the pixel area of each detected bounding box. This requires performing non-maximum suppression first. ```python results = model.infer(frame, confidence=0.002) detections = sv.Detections.from_inference(results).with_nms(threshold=0.1) detections.area ``` -------------------------------- ### Define Configuration Parameters Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/serialise-detections-to-json.ipynb Set up configuration parameters for the video processing pipeline, including source video path, confidence and IoU thresholds, output file name, and the inference model to use. ```python SOURCE_VIDEO_PATH = download_assets(VideoAssets.PEOPLE_WALKING) CONFIDENCE_THRESHOLD = 0.3 IOU_THRESHOLD = 0.7 FILE_NAME = "detections.json" INFERENCE_MODEL = "yolov8n-640" ``` -------------------------------- ### Initialize Model and Video Processing Components Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/object-tracking.ipynb Load a pre-trained model and initialize video processing utilities like VideoInfo, LabelAnnotator, and ByteTrack. Ensure the frame rate matches the video's FPS for accurate tracking. ```python from tqdm import tqdm # Load a pre trained yolov8 nano model from Roboflow Inference. model = get_roboflow_model('yolov8n-640') # Create a video info object from the video path. video_info = sv.VideoInfo.from_video_path(path_to_video) # Create a label annotator for labeling detections with our tracker_id. label = sv.LabelAnnotator() # Create a ByteTrack object to track detections. byte_tracker = sv.ByteTrack(frame_rate=video_info.fps) # Create a frame generator from video path for iteration of frames. frame_generator = sv.get_video_frames_generator(path_to_video) ``` -------------------------------- ### Initialize Annotators for Visualization Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/evaluating-alignment-of-text-to-image-diffusion-models.ipynb Set up `sv.BoundingBoxAnnotator` and `sv.LabelAnnotator` to draw bounding boxes and labels on the image. Customize thickness and text properties as needed. ```python bounding_box_annotator = sv.BoundingBoxAnnotator(thickness=2) label_annotator = sv.LabelAnnotator(text_thickness=1, text_scale=0.5,text_color=sv.Color.BLACK) ``` -------------------------------- ### Get Video Frames Generator Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/quickstart.ipynb Create a generator to iterate over frames of a video file. ```python from supervision.video.core import get_video_frames_generator for frame in get_video_frames_generator(source_path='your_video.mp4'): # Process each frame pass ``` -------------------------------- ### Import Necessary Libraries Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/zero-shot-object-detection-with-yolo-world.ipynb Import core libraries including cv2 for image processing, supervision for visualization, tqdm for progress bars, and YOLOWorld for the detection model. ```python import cv2 import supervision as sv from tqdm import tqdm from inference.models.yolo_world.yolo_world import YOLOWorld ``` -------------------------------- ### Predict Detections with RFDETR Model Source: https://github.com/roboflow/supervision/blob/develop/README.md Use the RFDETR model to predict detections from an image. Requires Pillow and rfdetr to be installed. ```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 ``` -------------------------------- ### Initialize YOLO-World Model Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/evaluating-alignment-of-text-to-image-diffusion-models.ipynb Load the YOLO-World model using its model ID. This is the first step to start object detection. ```python model = YOLOWorld(model_id="yolo_world/l") ``` -------------------------------- ### Run Detection with Inference Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/save_detections.md Initialize the Inference model and generate predictions from video frames. This sets up the detections object needed for saving. ```python import supervision as sv from inference import get_model model = get_model(model_id="yolov8n-640") frames_generator = sv.get_video_frames_generator("") for frame in frames_generator: results = model.infer(image)[0] detections = sv.Detections.from_inference(results) ``` -------------------------------- ### Using CompactMask with Detections Source: https://github.com/roboflow/supervision/blob/develop/examples/compact_mask/README.md Demonstrates how to use a CompactMask instance within the supervision.Detections object, highlighting its transparent integration. ```python # Use exactly like a dense mask — no other code changes needed: detections = sv.Detections(xyxy=xyxy, mask=compact, class_id=class_ids) ``` -------------------------------- ### Download Corgi v2 Dataset Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/benchmark_a_model.md A specific example of downloading the Corgi v2 dataset in YOLOv11 format using Roboflow. ```python from roboflow import Roboflow rf = Roboflow(api_key="") project = rf.workspace("fbamse1-gm2os").project("corgi-v2") dataset = project.version(4).download("yolov11") ``` -------------------------------- ### Generate Image with SDXL Source: https://github.com/roboflow/supervision/blob/develop/docs/notebooks/evaluating-alignment-of-text-to-image-diffusion-models.ipynb Generate an image using the initialized SDXL pipeline based on a detailed text prompt and negative prompt. This example specifies image dimensions and a seed for reproducibility. ```python PROMPT = "a black cat playing with a blue ball next to a parked white car, wide angle, photorealistic" NEGATIVE_PROMPT = "low quality, blurred, text, illustration" WIDTH, HEIGHT = 1024, 768 SEED = 9213799 image = pipeline( prompt=PROMPT, negative_prompt=NEGATIVE_PROMPT, generator=torch.manual_seed(SEED), width=WIDTH, height=HEIGHT, ).images[0] image ``` -------------------------------- ### Add with uv Source: https://github.com/roboflow/supervision/blob/develop/docs/index.md Use uv to add supervision as a dependency to your uv project. ```bash uv add supervision ``` -------------------------------- ### Save Detections with Generic Inference Source: https://github.com/roboflow/supervision/blob/develop/docs/how_to/save_detections.md Use `sv.CSVSink` to save detections from a generic inference model. Ensure you have the `inference` library installed and a model loaded. ```python import supervision as sv from inference import get_model model = get_model(model_id="yolov8n-640") frames_generator = sv.get_video_frames_generator("") with sv.CSVSink("") as sink: for frame in frames_generator: results = model.infer(image)[0] detections = sv.Detections.from_inference(results) sink.append(detections, {}) ```