The Little Car Counter

Before #highwayshack Highways England released lots of data on traffic flow and congestion on the UK's strategic road network. We loved what some of the other teams did with this, like predicting journey times based on historical data and tracking the current total minutes of delay on the whole network.

But most vehicle journeys in the UK aren't on the strategic road network, they take place on roads managed by a local authority. And there is very little data on congestion and flow for local roads.

So we created the Little Car Counter, a traffic monitoring system using an ordinary webcam to generate open data for upload to the web. In the future, we will port this to mobile phones and we imagine that the app will help people with local traffic campaigns. It could also help local authorities understand congestion and plan and justify traffic interventions.

The Little Car Counter is written in Visual Basic and Windows Forms and uses the live-feed from a webcam. Video is processed in real-time using the OpenCV library via the EmguCV .NET wrapper.

During testing we positioned our webcam on a ledge overlooking Duke Street in Leeds pointing at three lanes of traffic. Moving objects are identified and tracked into subsequent frames. You can see an example video frame below; once a moving target is recognised a red box surrounds the object, and a yellow point indicates its central point.

The red line across the top third of the frame represents a transition point and every vehicle that travels over this region is logged. We obtain several parameters from the video: the time of crossing, the vehicle size (the red box size), and its relative speed calculated by comparing the change in position between two consecutive frames. The last two measure need improving.

Each event is saved within a JSON object and this traffic data is posted in batches of thirty vehicles to an ElasticSearch instance on Amazon Web Services where it is stored. We visualised this data using Kibana and created a customisable dashboard that updates every 10 seconds.

Little car counter relies on the EmguCV .NET wrapper for OpenCV and we intend to port out solution to mobile phones as soon as Emgu is updated to support Universal Windows Platform.