This is a software written in python for use in counting vehicles from a pre-recorded traffic camera video.
Demo video: https://drive.google.com/file/d/1GImSkQ2CWaAPqje9_UJGZ80fDWFxbJfV/view
Instead of hardcoding and relying on scripts to get the job done, a GUI is preferred to make the tool easier to optimize and adapt to different scenarios of counting vehicles by using interactive graphical handles.
YoloV4 deep learning based object detection model is used for its good balance between accuracy and inference speed.
A pretrained model on MS COCO dataset allows easy vehicle detection
YoloV4 explaination: https://becominghuman.ai/explaining-yolov4-a-one-stage-detector-cdac0826cbd7
DeepSORT is a popular object detection algorithm that fuses Kalman filters & deep learning to identify and track object movement from frame to frame
DeepSORT explaination: https://nanonets.com/blog/object-tracking-deepsort/
YoloV4 and DeepSORT code are taken from: https://github.com/theAIGuysCode/yolov4-deepsort
A rectangle region of interest (ROI) is defined, such that when the centroid of the detection bounding box is present in the ROI for more than X frames, the vehicle is counted
A vector is defined with the following:
- Direction (travel direction of vehicle)
- Magnitude (pixels traveled by vehicle)
- width (tolerance of travel direction)
For each detection, the travel and direction is computed and filtered out based on the vector defined above.
The detection that passes the filter will be counted
- Python 3.8
- Pyside (Qt for Python)
- Tensorflow
- pyqtgraph
The GUI is designed with Qt designer, which is a drag and drop tool to arrange the components and skeleton of the application. The designer files are saved in a .ui
format, which needs to be converted to a python file by compile_ui.py
viewController.py
manages all user interaction behaviour and displays the content accordingly
model.py
encapsulates all the backend processing functionality and runs in a separate thread.
- When performing inference for the first time after software startup, expect to take ~1 minute for loading the model to GPU.
- Inference will also save the results to a hdf
.h5
file that can be used for offline analysis, because inference requires a lot of computing power - The hdf file save location defaults to the same folder as the input video file
- Tweak the counting algorithms' parameters and visualize the results imediately by using the saved inferenced results in the hdf file
conda env create -f conda-gpu.yml
conda activate trafficVehicleCounter-gpu
Save the checkpointsfolder to the root of the repo
https://drive.google.com/drive/folders/1f4NAGjFsVDrGNAJ52UX36LousG3tCsiA?usp=sharing
python run.py
designer
python compile_ui.py
- Training on actual data to better differentiate between vehicles
- Tuning of DeepSORT parameters for more accurate tracking, right now duplicate IDs will occur when video has too many vehicles that look similar
- Decouple the algorithms from PySide, encapsulate them as APIs
- Saving settings into a project file