This is the repository for my undergraduate research project "Traffic Event Detection Via Object Tracking" under the URECA program at NTU.
First run cd code
to navigate to the correct folder
usage: main.py [-h] mode video data tracks
positional arguments:
mode Pass either 'train' or 'test'
video Path to the video file
data Path where training data is stored or should be stored
tracks Path where tracking data is stored or should be stored
Example (training):
python main.py train ../data/main/video.mp4 ../data/main ../data/main/tracks.txt
orpython main.py train ../data/short/NoStall.avi ../data/short ../data/short
Example (testing):
python main.py test ../data/main/video.mp4 ../data/main/video_data.csv ../data/main/tracks.txt --anomalies=../data/main
orpython main.py test ../data/short/NoStall.avi ../data/short ../data/short/NoStall_data.csv --anomalies=../data/main
The objective of the project is to identify the following named events in traffic surveillance videos:
- Stalled Cars
- Over Speeding
- Wrong Direction Driving
- High Traffic Density
- ✔️The video is passed through a tracker like Deep SORT to get tracking information of the cars
- ✔️The tracker output is converted to a Pandas DataFrame
- ✔️The user is asked to draw the road masks for the scene
- ✔️The road masks will be used to generate 2D maps of each road through inverse perspective mapping
- ✔️The tracking data is again used to find the median speed, median direction, and median traffic density of each of the 2D maps of the roads of the video.
- ✔️For each video, the trained data will be saved as a CSV file with the following format:
Road ID | Bound 0 | Bound 1 | Bound 2 | Bound 3 | Speed Median | Speed SD | Direction Median | Direction SD | Traffic Median | Traffic SD |
---|---|---|---|---|---|---|---|---|---|---|
1 | [0, 0] | [0, 0] | [0, 0] | [0, 0] | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 | 1.0 |
- ✔️The video is passed through a tracker like Deep SORT to get tracking information of the cars
- ✔️The tracker output is converted to a Pandas DataFrame
- ✔️The training data CSV is used to reconstruct the 2D mapped roads
- ✔️For each frame, the Robust Z-Score Method is used to check if there are any anomalous speeds, or traffic levels (for direction, it is checked whether the magnitude of the value is more than 150 degrees as compared to the median). The object is marked as anomalous only if it is anomalous for all the roads in the scene.
- ✔️The background plate version of the video is exported and passed through a tracker to identify stalled cars
- ✔️The anomalous data is saved as a CSV file with the following format:
S. No. | Frame | Type | X | Y | Value | Road |
---|---|---|---|---|---|---|
1 | 174 | Stalled Car | 23 | 58 | -1 | 0 |
2 | 208 | Over-Speeding | 526 | 127 | 2.7 | 1 |
2 | 208 | Traffic | 0 | 0 | 4 | 0 |