Kenyan Developer Builds API to Give Road Traffic Updates Via Cameras

5
Nairobi Traffic
University Way, Nairobi, Kenya

Chris Orwa, a Kenyan Data Scientist seems to be tired of spending endless amounts of hours stuck in Nairobi traffic. Chris, has built an API that returns traffic conditions from Internet Solutions Kenya (formerly Access Kenya) cameras. Quick context, IS Kenya has installed traffic cameras across different parts of the city and has made them publicly available by streaming the content through a web portal. Chris is utilizing these cameras to be able to tell whether there is traffic or not, without having to go watch IS Kenya’s live stream.

To achieve this, Chris had to test if it is possible to capture an image from each of IS’ cameras. “After exploration of the website I realized each camera had a URL with a JPEG file extension at the end,” he says, “I figured the cameras wrote a new image to the JPEG file on the URL. So, can I captured every new image? Yes”

After this discovery, Chris organized the camera URLs into a list so as to have a means of calling and referencing each road. After organizing the URLs, he wrote a function that takes a URL and extracts three images every 6 seconds. The next step was to process the images and make meaning off them. “The first important step in analysis of the images is checking if there has been movements within the 6 second period,” he explains, “To achieve this, I utilized the concept of differential imaging – a means of measuring motion detection by subtracting the pixel values of subsequent images. In my function, I calculate the number of pixels that have moved, this helps in quantifying the movement (standstill, moderate traffic).”

Once movement is detected, Chris quantifies the movement of traffic in km/h. He does this by utlilizng the optical flow algorithm, a concept in computer vision that allows tracking features in an image. “I utilized this functionality to find features to track (cars) in the first images, and get their corresponding positions in the second and third image,” says Chris. “I then proceeded to calculate the average distance that the feature [car] has moved. Dividing the pixel distance by 12 seconds gives me speed at which the objects (cars) are moving.

The API (which is yet to be completed) returns the speed of traffic and the level of movement i.e. whether the cars are at a standstill, moderate movement or no traffic at all, when a user feeds the API with a road name.

Chris has open sourced the API, which is available at https://github.com/Python-Nairobi/ImPro.

More details about the API can be found on Chris’ blog post.

5 COMMENTS

  1. Good job Christ, next, make it available to the public through a twitter bot or an sms short code or even an app.

Comments are closed.