supervision/examples/count_people_in_zone
Jirka Borovec bcbe8de1e4
chore(pre-commit): remove unnecessary exclude rule for changelog... (#2452)
* chore(pre-commit): remove unnecessary exclude rule for changelog and deprecated docs
* docs(changelog): reformat code blocks for consistency and clarity
* docs(changelog): reformat and align code blocks for consistent indentation and readability
* chore(pre-commit): update mdformat hooks to include gfm and frontmatter extensions
* chore(pre-commit): split mdformat hook into gfm and mkdocs variants
* docs(changelog): fix nested code fences breaking mdformat-mkdocs
* fix(pre_commit): 🎨 auto format pre-commit hooks

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-21 19:33:35 +02:00
..
data fix(pre_commit): 🎨 auto format pre-commit hooks 2023-12-13 14:46:54 +00:00
.gitignore ready for review 2024-01-17 12:11:31 +01:00
README.md chore(pre-commit): remove unnecessary exclude rule for changelog... (#2452) 2026-07-21 19:33:35 +02:00
inference_example.py feat(utils): add `TkImageWindow` to unblock switch to `opencv-python-headless` (#2320) 2026-07-15 15:06:55 +02:00
requirements.txt examples/count_people_in_zone: resolve IoU threshold & improve CLI (#2054) 2026-02-03 11:35:09 +01:00
setup.sh Initial commit 🎉 2023-12-13 14:28:16 +01:00
ultralytics_example.py feat(utils): add `TkImageWindow` to unblock switch to `opencv-python-headless` (#2320) 2026-07-15 15:06:55 +02:00

README.md

count people in zone

Colab YouTube

👋 hello

This demo is a video analysis tool that counts and highlights objects in specific zones of a video. Each zone and the objects within it are marked in different colors, making it easy to see and count the objects in each area. The tool can save this enhanced video or display it live on the screen.

https://github.com/roboflow/supervision/assets/26109316/f84db7b5-79e2-4142-a1da-64daa43ce667

💻 install

  • clone repository and navigate to example directory

    git clone --depth 1 -b develop https://github.com/roboflow/supervision.git
    cd supervision/examples/count_people_in_zone
    
  • setup python environment and activate it [optional]

    uv venv
    source .venv/bin/activate
    
  • install required dependencies

    uv pip install -r requirements.txt
    
  • download traffic_analysis.pt and traffic_analysis.mov files

    ./setup.sh
    

🛠️ script arguments

  • ultralytics

    • --source_weights_path (optional): The path to the YOLO model's weights file. Defaults to "yolov8x.pt" if not specified.

    • --zone_configuration_path: Specifies the path to the JSON file containing zone configurations. This file defines the polygonal areas in the video where objects will be counted.

    • --source_video_path: The path to the source video file that will be analyzed.

    • --target_video_path (optional): The path to save the output video with annotations. If not provided, the processed video will be displayed in real-time.

    • --confidence_threshold (optional): Sets the confidence threshold for the YOLO model to filter detections. Default is 0.3.

    • --iou_threshold (optional): Specifies the IOU (Intersection Over Union) threshold for the model. Default is 0.7.

  • inference

    • --roboflow_api_key (optional): The API key for Roboflow services. If not provided directly, the script tries to fetch it from the ROBOFLOW_API_KEY environment variable. Follow this guide to acquire your API KEY.

    • --model_id (optional): Designates the Roboflow model ID to be used. The default value is "yolov8x-1280".

    • --zone_configuration_path: Specifies the path to the JSON file containing zone configurations. This file defines the polygonal areas in the video where objects will be counted.

    • --source_video_path: The path to the source video file that will be analyzed.

    • --target_video_path (optional): The path to save the output video with annotations. If not provided, the processed video will be displayed in real-time.

    • --confidence_threshold (optional): Sets the confidence threshold for the YOLO model to filter detections. Default is 0.3.

    • --iou_threshold (optional): Specifies the IOU (Intersection Over Union) threshold for the model. Default is 0.7.

📌 zone configuration

  • horizontal-zone-config.json: Defines zones divided horizontally across the frame.
  • multi-zone-config.json: Configures multiple zones with custom shapes and positions.
  • quarters-zone-config.json: Splits the frame into four equal quarters.
  • vertical-zone-config.json: Divides the frame into vertical zones of equal width.

⚙️ run example

  • ultralytics

    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
    
  • inference

    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
    

© license

This demo integrates two main components, each with its own licensing:

  • ultralytics: The object detection model used in this demo, YOLOv8, is distributed under the AGPL-3.0 license. You can find more details about this license here.

  • supervision: The analytics code that powers the zone-based analysis in this demo is based on the Supervision library, which is licensed under the MIT license. This makes the Supervision part of the code fully open source and freely usable in your projects.