This project imlements the following tasks in the project: 1. Vehicle counting, 2. Lane detection. 3.Lane change detection and 4.speed estimation
This project uses YOLOv3 for Vehicle detection and SORT(Simple Online and Realtime Tracker) for vehicle tracking
This project imlements the following tasks in the project:
link to the original video: https://youtu.be/PSf09R3D7Lo | updated gdrive link
link to the ouput video: gdrive link
Note that there are 4 locations in the video and so the code(4 IFs), you can delete 3 and edit the first one according to your need.
$ git clone https://github.com/bamwani/car-counting-and-speed-estimation-yolo-sort-python
$ cd car-counting-and-speed-estimation-yolo-sort-python/
$ pip3 install -r requirements.txt
$ bash download_weights
Make sure you change the line of detection and lane segmentation according to your video and fine tune the threshold and confidence for YOLO model
Run
$ Python3 main.py -input /path/to/video/file.avi -output /path/for/output/video/file.avi -yolo /path/to/YOLO/directory/
This is an interesting project, mainly due to camera shaking(maybe due to wind or whaterver the reason may be!). This camera shake results into frame flickering. Which means we can not use traditional pixel distance travelled to Km/h mapping because as each frame flickers, the centroid of the bounding box also flickers arbitrarily. Hence I tried this new method: SPEED BETWEEN TWO LINES
This method makes some assumptions which are as follows:
--> We draw two lines on the frame perpendicular to the vehicle moving directon, then we find the minimim time taken by any car to cross these two lines(This car will be moving at the speed limit). Once we find he minimum time required for a car to pass these two lines, we use simple speed=distance/time formula to calculate the speed for rest of the cars.[ I know this wouldn't be perfect, but surely much more precise than the pixel mapping method]
I will try to keep making commits to improve the speed detection of vehicles. Any pull request for improvement is highly welcomed.