{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "TfUZYrKbqlF7" }, "source": [ "# Annotate Video with Detections\n", "\n", "---\n", "\n", "[](https://colab.research.google.com/github/roboflow/supervision/blob/develop/docs/notebooks/annotate-video-with-detections.ipynb)\n", "\n", "One of the most common requirements of computer vision applications is detecting objects in images and displaying bounding boxes around those objects. In this cookbook we'll walk through the steps on how to utilize the open source Roboflow ecosystem to accomplish this task on a video. Let's dive in!" ] }, { "cell_type": "markdown", "metadata": { "id": "rUo1u17yqlF9" }, "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": "0Er370WTqlF9", "outputId": "57b00a1e-87ea-4912-b4f9-5b94f0e6bf48", "vscode": { "languageId": "shellscript" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fri Feb 23 03:15:00 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": "WuSnN7ejqlF-" }, "source": [ "## Installing Dependencies\n", "\n", "In this cookbook we'll be utilizing the open source packages [Inference](https://inference.roboflow.com/) and [Supervision](https://supervision.roboflow.com/latest/) to accomplish our goals. Let's get those installed in our notebook with pip." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "1YgQGum4qlF-", "vscode": { "languageId": "shellscript" } }, "outputs": [], "source": [ "!pip install -q inference-gpu \"supervision\"" ] }, { "cell_type": "markdown", "metadata": { "id": "PZRnzh7EqlF-" }, "source": [ "## Download a Video Asset\n", "\n", "First, let's download a video that we can detect objects in. Supervision comes with a great utility called Assets to help us hit the ground running. When we run this script, the video is saved in our local directory and can be accessed with the variable `path_to_video`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "NMg4KOFiqlF-" }, "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": "x93oxF0zrQOU" }, "source": [ "As a result, we've downloaded a video. Let's take a look at the video below. Keep in mind that the video preview below works only in the web version of the cookbooks and not in Google Colab.\n", "\n", "