This repository contains code for object detection and tracking in videos using the YOLOv9 object detection model and the DeepSORT algorithm.
This repository contains code for object detection and tracking in videos using the YOLOv9 object detection model and the DeepSORT algorithm.
git clone https://github.com/sujanshresstha/YOLOv9_DeepSORT.git
cd YOLOv9_DeepSORT
conda env create -f conda.yml
conda activate yolov9-deepsort
python3 -m virtualenv -p python3.11 yolov9-deepsort
source yolov9-deepsort/bin/activate
pip install -r requirements.txt
git clone https://github.com/WongKinYiu/yolov9.git
cd yolov9
pip install -r requirements.txt
mv ../object_tracking.py ../yolov9
mkdir weights
wget -P weights https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-e.pt
Prepare the video file:
video
flag in the path of the video file or set it to 0
to use the webcam as the input.Download YOLOv9 model:
Configure the output video:
output
flag in the code to specify the path and filename of the output video file.Set the confidence threshold:
conf
flag in the code to set the confidence threshold for object detection. Objects with confidence below this threshold will be filtered out.If you want to detect and track certain object on video
class_id
flag in the code to specify the class ID for detection. The default value of the flag is set to None. If you wish to detect and track only persons, set it to 0, or refer to the coco.names file for other options.If you want to blur certain object while tracking
bulr_id
flag in the code to specify the class ID for detection. The default value of the flag is set to None.Run the code:
# Run object tracking
python object_tracking.py --video ./data/test.mp4 --output ./output/output.mp4
# Run object tracking on webcam (set video flag to 0)
python object_tracking.py --video 0 --output ./output/webcam.mp4
# Run person tracking (set class_id flag to 0 for person)
python object_tracking.py --video ./data/test.mp4 --output ./output/output.mp4 --class_id 0
# Run tracking on a video with burring certain objects (set blur_id flag to 0 for person)
python object_tracking.py --video ./data/test.mp4 --output ./output/output.mp4 --blur_id 0