{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "BsraWznGULVc" }, "source": [ "# Object Tracking\n", "\n", "---\n", "\n", "[](https://colab.research.google.com/github/roboflow/supervision/blob/develop/docs/notebooks/object-tracking.ipynb)\n", "\n", "In some cases, it's important for us to track objects across multiple frames of a video. For example, we may need to figure out the direction a vehicle is moving, or count objects in a frame. Some Supervision [Annotators](https://supervision.roboflow.com/latest/detection/annotators/) and Tools like [LineZone](https://supervision.roboflow.com/latest/detection/tools/line_zone/) require tracking to be setup. In this cookbook, we'll cover how to get a tracker up and running for use in your computer vision applications.\n", "\n", "## What is a Tracker?\n", "\n", "Trackers are a piece of code that identifies objects across frames and assigns them a unique `tracker_id`. There are a few popular trackers at the time of writing this including ByteTrack and Bot-SORT. Supervision makes using trackers a breeze and comes with ByteTrack built-in." ] }, { "cell_type": "markdown", "metadata": { "id": "7h__vutkUZSY" }, "source": [ "## Before you start\n", "\n", "Let's make sure that we have access to GPU. We can use `nvidia-smi` command to do that. In case of any problems navigate to `Edit` -> `Notebook settings` -> `Hardware accelerator`, set it to `GPU`, and then click `Save`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "pzm2gQlYUbmd", "outputId": "71217cbf-f7d0-4496-c150-1c363386a16f", "vscode": { "languageId": "shellscript" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fri Feb 23 03:18:02 2024 \n", "+---------------------------------------------------------------------------------------+\n", "| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |\n", "|-----------------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|=========================================+======================+======================|\n", "| 0 Tesla V100-SXM2-16GB Off | 00000000:00:04.0 Off | 0 |\n", "| N/A 33C P0 24W / 300W | 0MiB / 16384MiB | 0% Default |\n", "| | | N/A |\n", "+-----------------------------------------+----------------------+----------------------+\n", " \n", "+---------------------------------------------------------------------------------------+\n", "| Processes: |\n", "| GPU GI CI PID Type Process name GPU Memory |\n", "| ID ID Usage |\n", "|=======================================================================================|\n", "| No running processes found |\n", "+---------------------------------------------------------------------------------------+\n" ] } ], "source": [ "!nvidia-smi" ] }, { "cell_type": "markdown", "metadata": { "id": "ZI4EwAnEUTFC" }, "source": [ "## Install Dependencies" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "NaEjHlAWULVd" }, "outputs": [], "source": [ "!pip install -q inference-gpu \"supervision\"" ] }, { "cell_type": "markdown", "metadata": { "id": "zUKICBWFULVe" }, "source": [ "## Download a Video Asset\n", "\n", "Now that we have our environment setup, lets download a video that we can detect objects in. Supervision comes with a great utility to help us hit the ground running. We can use the below snippet to he video is save a video asset in our local directory. It can also be accessed with the variable `path_to_video` for additional application logic." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "MyNzGpzOULVe" }, "outputs": [], "source": [ "from supervision.assets import download_assets, VideoAssets\n", "\n", "# Download a supervision video asset\n", "path_to_video = download_assets(VideoAssets.PEOPLE_WALKING)" ] }, { "cell_type": "markdown", "metadata": { "id": "0cMveUy5U-tN" }, "source": [ "