Implementation of Real-Time Object Tracking using YOLOv10 and DeepSORT Algorithm

Posted by


Real-time object tracking is a crucial task in computer vision applications such as surveillance, automated driving, and augmented reality. In this tutorial, we will learn how to perform real-time object tracking using YOLO10 (You Only Look Once) object detection algorithm and DeepSORT (Deep Learning for Object Tracking) algorithm.

YOLO10 is a state-of-the-art object detection algorithm that can detect and classify multiple objects in an image with high accuracy and speed. DeepSORT is a tracking algorithm that extends the capabilities of YOLO10 by associating detections with unique object identities and tracking them over time.

To get started, you will need to have the following prerequisites:

  1. A computer with a GPU (NVIDIA GPU is recommended for faster performance)
  2. Python programming language installed on your system
  3. OpenCV library for image processing
  4. YOLOv10 weights and configuration files
  5. DeepSORT library

Let’s start by installing the required libraries. You can install OpenCV using pip:

pip install opencv-python

Next, you will need to download the YOLOv10 weights and configuration files from the official website:

wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.cfg
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.names

You can also download the pre-trained DeepSORT model from GitHub:

git clone https://github.com/nwojke/deep_sort.git

Now, let’s create a Python script to load the YOLOv10 model and perform object detection:

import cv2
import numpy as np

# Load YOLOv10 weights and configuration
net = cv2.dnn.readNet("yolov4.weights", "yolov4.cfg")
classes = []
with open("yolov4.names", "r") as f:
    classes = [line.strip() for line in f.readlines()]
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]

# Load DeepSORT model
tracker = cv2.TrackerCSRT_create()

# Load video file
cap = cv2.VideoCapture('video.mp4')

while(cap.isOpened()):
    ret, frame = cap.read()
    if not ret:
        break

    # Perform object detection
    height, width, channels = frame.shape
    blob = cv2.dnn.blobFromImage(frame, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
    net.setInput(blob)
    outs = net.forward(output_layers)

    # Process detection results
    for out in outs:
        for detection in out:
            scores = detection[5:]
            class_id = np.argmax(scores)
            confidence = scores[class_id]
            if confidence > 0.5:
                # Object detected
                center_x = int(detection[0] * width)
                center_y = int(detection[1] * height)

                # Draw bounding box
                w = int(detection[2] * width)
                h = int(detection[3] * height)
                x = int(center_x - w / 2)
                y = int(center_y - h / 2)
                cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
                cv2.putText(frame, classes[class_id], (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)

                # Track object using DeepSORT
                tracker.init(frame, (x, y, w, h))

    cv2.imshow('Object Tracking', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

This script reads a video file frame by frame, performs object detection using YOLOv10, and then tracks the objects using DeepSORT. You can customize this script to suit your specific requirements and use cases.

In conclusion, this tutorial has covered the basics of real-time object tracking using YOLO10 and DeepSORT algorithms. By following these steps and experimenting with the code, you can build robust object tracking systems for various applications. It is recommended to explore more advanced techniques and fine-tune the models to achieve better performance and accuracy. Happy coding!

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@muhammadmoinfaisal
1 month ago

🧑🏻‍💻 My AI and Computer Vision Courses⭐:

📙 YOLOv9: Learn Object Detection, Tracking with WebApps (13$):

https://www.udemy.com/course/yolov9-learn-object-detection-tracking-with-webapps/?couponCode=JULY13DOLLARS

📕 Learn LangChain: Build #22 LLM Apps using OpenAI & Llama 2 (14$):

https://www.udemy.com/course/learn-langchain-build-12-llm-apps-using-openai-llama-2/?couponCode=JULY13DOLLARS

📚 Computer Vision Web Development: YOLOv8 and TensorFlow.js (13$):

https://www.udemy.com/course/computer-vision-web-development/?couponCode=JULY13DOLLARS

📕 Learn OpenCV: Build # 30 Apps with OpenCV, YOLOv8 & YOLO-NAS (13$):

https://www.udemy.com/course/learn-opencv-build-30-apps-with-opencv-yolov8-yolo-nas/?couponCode=JULY13DOLLARS

📗 YOLO-NAS, OpenAI, SAM with WebApps using Flask and Streamlit (13$): https://www.udemy.com/course/yolo-nas-object-detection-tracking-web-app-in-python-2023/?couponCode=JULY13DOLLARS

📘 YOLO-NAS The Ultimate Course for Object Detection & Tracking (13$): https://www.udemy.com/course/yolo-nas-the-ultimate-course-for-object-detection-tracking/?couponCode=JULY13DOLLARS

📙 YOLOv8: Object Detection, Tracking & Web Apps in Python 2023 (13$) : https://www.udemy.com/course/yolov8-the-ultimate-course-for-object-detection-tracking/?couponCode=JULY13DOLLARS

📚 YOLOv7 YOLOv8 YOLO-NAS: Object Detection, Tracking & Web Apps in Python 2023 (13$): https://www.udemy.com/course/yolov7-object-detection-tracking-with-web-app-development/?couponCode=JULY13DOLLARS

@user-si1sj7kw4h
1 month ago

Is it possible to integrate DeepSORT to another model which is not yolov8?
I am working on an external model called "DAMO-YOLO", it does not use ultralytics. Can i integrate DeepSORT into my program because this model does not have an inbuilt tracker.

@arifkhan-jz9vf
1 month ago

sir plz add your udemy courses to personal planes