Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!

Use OpenCV to See How Many Cars Speed Past Your House

Adrian Rosebrock has put together a tutorial that will walk you through how to detect vehicles and then track them to estimate their speed.

Cameron Coward
5 years agoSensors / Automotive

Computer vision itself isn’t anything new, but it has only recently reached a point where it’s practical for hobbyists to utilize. Part of that is because hardware has improved dramatically in recent years, but it also helps that good open-source machine learning and computer vision software has become available. More software options are becoming available, but OpenCV is one that has been around for a while now and is still one of the most popular. Over on PyImageSearch, Adrian Rosebrock has put together a tutorial that will walk you through how to detect vehicles and then track them to estimate the speed at which they’re traveling.

Rosebrock’s guide will show you how to make your very own DIY speed camera. But even if that isn’t something you have a need for, the tutorial is worth following just to learn some useful computer vision techniques. You could, for instance, modify this setup to count how many cars enter and exit a parking lot. This can be done with affordable and readily-available hardware, so the barrier to entry is low — perfect for the kind of project that is more of a learning experience than anything else.

To do this, you’ll need a Raspberry Pi 4 Model B, an Intel Movidius NCS2 (Neural Compute Stick), and a camera like the official one available from Raspberry Pi. The Neural Compute Stick will help handle some the heavy lifting of the processing needed for deep learning. This relies on a process used on devices that police take advantage of to determine your speed, called VASCAR (Visual Average Speed Computer and Recorder). It’s a really simple principle: measure the amount of time it takes the vehicle to go from Point A to Point B. Those are usually landmarks like a street sign. As long as you know exactly how far apart they are and measure the elapsed time precisely, you can get an accurate speed reading.

In this case, you’ll be using four points to calculate an average speed across the entire video frame. You’ll use a combination of OpenCV running on the Raspberry Pi with OpenVINO for the Neural Compute Stick. The code to handle the job is provided, but you’d gain the most benefit by working through it yourself so you actually understand what’s happening. In the end, you should have a computer vision setup that can reliably and accurately determine how fast cars are moving, as well as some new skills.

Cameron Coward
Writer for Hackster News. Proud husband and dog dad. Maker and serial hobbyist. Check out my YouTube channel: Serial Hobbyism
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles