Inspiration
"It was around 7 o'clock. After a long day at university, I was riding my bike and I noticed at one of the intersections there was a green light for a completely empty road whilst the other was completely clogged up. As I passed by with ease, I witnessed the angry, tired commuters groan and sigh as they all glared at that unforgiving red light for what was definitely eternity. Ever since that day, I've decided to make a change." - Jacob Wisniewski, Project Manager.
We've all seen intersections that we believe could have better traffic light control. There are already some adaptive controls in place, such as different timings during different hours of the day to anticipate usual traffic flow, and plates under roads to detect the existence of a car. However, we believe there is a better solution, and it utilises realtime data.
What it does
Instead of the government spending billions of dollars on building new infrastructure - such as new streets and highways - to improve traffic flow, Intersect is an inexpensive improvement to existing infrastructure that dynamically handles traffic flow by using computer vision and machine learning.
What is Intersect, exactly? A Raspberry Pi, a camera, a database and an algorithm.
The Pi's, each connected to cameras, are placed up roads that lead into intersections. The Pi's then use computer vision to analyse the flow of cars in each lane and continually updates the database.
How we built it
Lane traffic analysis
As the Pi's/cameras are always still, we were able to use simple image processing techniques using OpenCV to isolate and count the vehicles in each lane. We could extract a background image despite an object always being in frame by accumulating a weighted average of each frame, setting up for the use of blob detection to identify moving vehicles. Given the number of lanes, we could use cluster analysis to categorise cars into each lane.

Background frame generated by accumulated weighted average of processed frames. [Video source]

Blobs detected by subtracting from background frame and applying a threshold value.

Counting cars by checking for blobs passing a certain line and using smallest distance to assign cars to the right lanes.
Machine learning algorithm and Traffic Simulator
The machine learning algorithm utilised a reinforcement-learning algorithm called Q-Learning. A simplified model of the traffic intersection was created in Python to simulate what interactions would occur between traffic light changes and cars inside intersections. The model was trained across 1,000,0000+ simulations in the test environment before handling real-time traffic feed data from the IoT devices.

The above image represent the ML during initial tests during the simulation. Improvement was generally linear as learning was still in its early stages. The y-axis of the graph represents how long the model has survived.

As the testing progressed, a exponential improvement in the algorithm was shown.

This improvement continued further even into the later tests, significantly improving the ML model.
Database
We used Firebase for our realtime database to store data about current traffic, as in the number of cars in each lane on each road, and traffic management, as in the state of the traffic lights at an intersection. This serves as a connection between our backend and frontend.
Frontend
The frontend we built was used to intuitively display how our system handled traffic by connecting to the realtime database provided by Firebase. In addition to being a fantastic visualisation tool, it is a good way to show how our system works to the general public.

This is a photo of the trained model working on a live traffic handling situation.
Challenges we ran into
We initially approached lane detection with a computer vision approach, however we couldn't get it working with our video feed. Instead, we came up with a more statistical approach that took a sample of blob midpoints and used cluster analysis to find k number of average midpoints given k lanes.
The model complexity we faced at first was too much for the reinforcement-learning algorithm to cope with in reasonable time so we had to re-evaluate our goals accordingly.
Our original design for the frontend ended up being harder to implement than we thought. We had to adapt and simplify our design to have a working frontend by the deadline.
Accomplishments that we're proud of
We got the computer vision/lane traffic analysis to work pretty early into the hack.
"Machine learning. It's just amazing, dude." - Abhi, Assistant Admin.
"Sexy name." - Jord, CIO.
What we learned
If your original idea doesn't work, you can always adapt and/or simplify.
There are limitations to React, especially with complex animations.
What's next for Intersect
More integrated detection of vehicles with tech that detects wifi and bluetooth signals as cars stop at intersections.
Log in or sign up for Devpost to join the conversation.