This project estimates the speed of objects in a video using YOLOv9 for object detection and DeepSORT for tracking. The estimated speeds are overlaid on the video along with bounding boxes around the detected objects.
- Clone this repository:
git clone https://github.com/kardSIM/Vehicle_Speed_Estimation.git
cd Vehicle_Speed_Estimation
- Create new environment:
- Using Conda
conda env create -f conda.yml
conda activate yolov9-deepsort
- Using pip
python3 -m virtualenv -p python3.11 yolov9-deepsort
source yolov9-deepsort/bin/activate
pip install -r requirements.txt
- Install YOLOv9 dependency:
pip install -r yolov9/requirements.txt
- Download model weights:
mkdir weights
wget -P weights https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-e.pt
- Download input video:
mkdir content
wget -P content https://github.com/AarohiSingla/Speed-detection-of-vehicles/raw/main/highway.mp4
wget -P content https://github.com/AarohiSingla/Speed-detection-of-vehicles/raw/main/highway_mini.mp4
- Test the program:
python3 object_tracking.py
-
Prepare the video file:
- Place the video file in the desired location.
- Update the
video
flag in the path of the video file.
-
Download YOLOv9 model:
-
Configure the output video:
- Update
output
flag in the code to specify the path and filename of the output video file.
- Update
-
Transforming Road Image to Bird's Eye View:
- Update the source points
SOURCE_POLYGONE
and destination pointsBIRD_EYE_VIEW
corresponding to the appropriate dimensions of the road.
- Update the source points
-
Modify source points (optional):
- Use the
click
flag argument to set newSOURCE_POLYGONE
. Right-click with the mouse on each point, then set the appropriateHEIGHT
andWIDTH
values.
- Use the
-
Set the confidence threshold:
- Adjust the
conf
flag in the code to set the confidence threshold for object detection. Objects with confidence below this threshold will be filtered out.
- Adjust the
-
If you want to detect and track certain object on video
- Modify the
class_id
flag in the code to specify the class ID for detection. The default value of the flag is set to None.
- Modify the
-
If you want to blur certain object while tracking
- Modify the
bulr_id
flag in the code to specify the class ID for detection. The default value of the flag is set to None.
- Modify the
-
Run the code:
# Run object tracking python3 object_tracking.py # Run on another file python3 object_tracking.py --video ./data/test.mp4 --output ./output/output.mp4 #Modify source points python3 object_tracking.py --click # Run car tracking (set class_id flag to 2 for car) python3 object_tracking.py --class_id 2 # Run tracking on a video with burring certain objects (set blur_id flag to 7 for truck) python3 object_tracking.py --blur_id 7
- This code is built upon the YOLOv9 model and the DeepSort algorithm.
- Credits to the authors and contributors of the respective repositories used in this project.