Count Objects Using YOLO V8 and Deep SORT | ai counting cars and peoples

Hello everyone, Anurag welcomes you all.

In this article, I will explain how to detect, track, and count objects using YOLO V8 and the Deep SORT algorithm.

All the necessary code is available in on my other upcoming blogs which you can clone to follow along. The Deep SORT code is stored in a specific folder, and the Jupyter Notebook used in this tutorial is also included.

Setting Up the Environment

Before diving into object detection and tracking, ensure that your environment is correctly set up. Here are the required versions:

  • Python Version: 3.9.10
  • Ultralytics Version: 8.0.106
    • Install it using: pip install ultralytics mentioned below.
    • pip install ultralytics
    • This package is necessary for YOLO V8.
  • Torch Version: 2.0.1 (compiled with CUDA 11.7)
  • GPU Used: RTX 3090
Ultralytics Version:
Ultralytics Version:

For those using a CPU, install a compatible Torch version. If using a GPU, check your CUDA version and install the appropriate PyTorch version accordingly.

Running YOLO V8

Now, let’s begin the object detection process. First, navigate to the folder containing all the necessary files and import the required modules.

  • The Jupyter Notebook provided in the repository will be used.
  • The primary goal is to use YOLO V8 to detect objects and extract:
    • Bounding box coordinates
    • Confidence scores
    • Detected classes

These variables are crucial for tracking.

In this tutorial, Anurag will focus on detecting people using YOLO V8. The COCO dataset pre-trained model contains a person class, which will be used here.

Here’s how the model is applied:

The output image with detections will be saved in the runs/detect/predict folder.

Applying the Deep SORT Algorithm

After detection, the next step is to track objects using the Deep SORT algorithm.

Processing a Video for Detection and Tracking

I will now demonstrate how to track and count objects in a video dataset.

  1. Load the video dataset and retrieve its frame width, height, and FPS.
  2. Save the processed output after detection, tracking, and counting.
  3. Use unique track IDs to count distinct objects.

Each frame is processed as follows:

Tracking IDs ensure each detected person is counted only once.

Displaying the Results

Each tracked object is assigned a unique ID and a bounding box.

The total number of people in the frame is counted and displayed.

The final output dataset contains all detected objects with their assigned tracking IDs.

Example Output:

Total Person Count: 4

Person 1 → ID: 4

Person 2 → ID: 3

Person 3 → ID: 2

Conclusion

In this article, Anurag has demonstrated how to use YOLO V8 and Deep SORT to:

This technique is useful for applications like crowd analysis, traffic monitoring, and security surveillance.

If any new AI company needs marketing services, contact Global Reputation Guru. Anurag and the team provide marketing solutions worldwide to help AI businesses grow.

For inquiries, visit www.globalreputationguru.com or email info@globalreputationguru.com.

Let me know if you need any further modifications.

Leave a Reply

Your email address will not be published. Required fields are marked *

×

Hello!

Click one of our contacts below to chat on WhatsApp

× Live Chat