Real-time Traffic Monitoring System using Python

Source: Deep Learning on Medium

Go to the profile of Gautam Kumar

Due to increase in population, number of vehicles on the road has increased. Also there is a rush on the road specially at traffic while crossing signals. At traffic signals there is always high chance of accident due to breaking traffic rules by drivers and pedestrians. Therefore to insure safety at road it is important to manage it well and continuously monitor it. In case if any mishap happen, immediate action should be taken to save precious lives. However, managing and monitoring traffic is very difficult and it require human effort. Generally, official used CCTV camera to see live frames but it requires human effort to monitor it. It became difficult to manage if one need to count how many cars crossed a particular street in a day? What is the frequency of people crossing signals? Answers of these questions help to decide weather this area is accidental prone or not.

Now a days traffic signals and sign board are placed to manage traffic and avoid accidents. However, sometimes driver can’t see the sign board such as ‘speed breaker’ and drive car without slowing it down which results accident on the road. Sometimes, driver can not see a person who is walking beside road or crossing signals causes accidents and sometimes driver can’t take instant decision to avoid accidents.

One solution of these problems may be if a system should detect persons walking beside road/crossing signals, vehicles passing through street, traffic signs such as speed breaker, speed limit, U-turn prohibited than and help driver by converting detected objects into audio signals so that even if driver can not see objects system wolud remind them. This concept can also be used in automatic driving applications. This system can also be used to monitor traffic on the road.

Here, a real time traffic monitoring application is developed using python. I have trained a faster R-CNN model with car, bus, truck, persons and few traffic signs such as ‘speed limit’ and ‘U-turn prohibited’. Detail about faster R-CNN netowk can be studied in [1]. Developed system can detect objects in live video streams, pre-recorded video and captured image. I used 200 images and annotated with labelimg tool available at my GitHub repository. Annotation of image is time consuming and it took around 4 hours for me to annotate 200 image manually. I trained model with 30k steps and it took around 20 hrs at my CPU with 6GB RAM. It is suggested to train your own model with up to 40k steps if your database size is large. Following figures shows outputs of the application when tested it with image and video.

Outputs of system when tested with image

You can download source code of this real-time traffic monitoring application from my GitHub repository and use it to train CNN model with own dataset. Thanks for excellent tutorial by Evan, from

Output of system when tested with video


Autonomous vehicles is next generation of future road traffic, This concept can be used to develop self driving cars, in fact, Tesla already tested automated vehicles but still need improvements.