This is a bicycle dashcam application, running on the Raspberry Pi, with Pi Camera, controllable via a browser/smartphone, capable of recognizing car license plates with OpenALPR, written in Node.
Currently, it can take and process an image every 10 seconds (Pi 3). The quality of the images taken by the Pi Camera while riding my bike are of insufficient quality for OpenALPR.
Beyond plate recognition, I see potential for:
- Record the speed of the cars around you
- Record the proximity of the cars around you
- A car driver readable display, ie: “Driver ABCD1234, your current speed is 45”. Like a mobile Toronto Watch Your Speed program sign. Would a driver allow a cyclist more space if they were aware their actions are being logged?
- Log this data on a remote server
- Share this data, with a group. Perhaps associate “near miss” data from many cyclists, and identify troublesome areas, or troublesome cars.
At the 3:55 mark in the marketing video, I THEN see the board mounted to a bicycle saddle, which is EXACTLY what I want to do:
I went to see what I could find about the developers, and read about them on TechCrunch:
“The actual device and onboard AI were created by Luxonis, which previously created the CommuteGuardian, a sort of smart brake light for bikes that tracks objects in real time so it can warn the rider. The team couldn’t find any hardware that fit the bill so they made their own, and then collaborated with OpenCV to make the OAK series as a follow-up.”
This is pretty exciting – CommuteGuardian is the first project I’ve come across with similar goals to mine: Prevent and Deter Car-Bicycle accidents. I exchanged a few emails with Brandon Gilles, the Luxonis CEO, and he shared some background – they also checked out OpenALPR, and started work on mobile phone implementations, but decided to move to a custom board when the Myriad X processor was launched.
I decided to back Luxonis’ Oak project. I’ll have to learn some new tools, but this board will be much faster than the Pi for image analysis (much faster than the 1 frame per 8 seconds I’m getting now!). The stereo vision capabilities on the Oak-D will allow for depth mapping, a capability for which I had previously been considering adding a LIDAR sensor. Looking forward to receiving my Oak-D, hopefully in December. In the interim, I’ll continue to experiment with different license plate recognition systems, read more about the tooling I can use with Oak-D, and perhaps try a different camera module on the Pi.
On a sunny mid-June Saturday, I took my bike for a ride down Yonge St to lake Ontario with my bicycle dashcam, testing my latest changes (May 18th). Over the course of a 2 hour ride, taking a photo about every 10 seconds:
Reviewing the photos with my own eyes, I can make out about 45 images with readable plates (not every image was usable or had a car in the photo)
Of these 45, OpenALPR can make out about 10
I’m going to try running these photos through alternate ALPR engines, and compare results.
On this run, I tested the Pi Camera V2’s various sensor modes: the streaming modes at 1920×1080 30 fps, 3280×2464 15 fps, 640×922 30 fps, 1640×922 40 fps, 1280×720 41 fps, 1280×720 60 fps, as well as the still mode at 3280×2464. Further testing is likely still required, but I continue to get the best results from the still mode – all of the successful matches were shot using still mode.
I’m getting better results than I had on previous runs as a result of tweaking the pi-camera-connect NodeJS library to:
use a 5 second capture delay, which allows exposure time, gain, and white balance to be determined
set the exposure mode to sports, which reduces motion blur by preferentially increasing gain rather than exposure time
However, the images are still not as good as I would like.
8 MP is suggested for highway or street monitoring – the Pi Camera is sufficient in this regard
Zoom – I think this is a challenge in my setup – I liked the idea of getting everything around me, but I think I have to reduce the area I capture to get a view of the plate with more detail. Perhaps focus to my “7 o’clock” rather than capture everything behind me.
At 30 mph (~45 km/hr), which probably covers most bike riding in traffic, they suggest at least 3 to 5 frames at 15-25 frames per second.
I might order the latest Pi camera with the zoom lens and see if I get better results.
In February, I saw Robert Lucian's Raspberry Pi based license plate reader project on Hackaday. His project is different, in that he wrote his own license plate recognition algorithm, which runs in the cloud - the Pi feeds the images to the cloud for processing. He had great results - 30 frames per second, with 1 second of latency. This is awesome, but I want to process on the device - I want to avoid cellular data and cloud charges. Once I get this working, I'll look at improving performance with a more capable processor, like the nVidia Jetson or the Intel Neural compute stick.
In any case, Robert was getting great images from his Pi - so I asked him how he did it. He wrote me back with a few suggestions - he is using the Pi camera in stream mode 5 at 30 fps.
I wondered if one of the issues was my Pi Camera (v1), so I ordered a version 2 camera (just weeks before the HQ camera came out!). The images I was getting still weren't great. I'm using the pi-camera-connect package, here's what I've learned so far:
Some of the modes are capable of higher frames per second, but results may be poor. Start with 30 fps
In stream mode, streamCamera.startCapture() must be called 2-3 seconds before streamCamera.takeImage()
There are a number of parameters not exposed by the pi-camera-connect package, but ultimately, this package is just a front end for raspistill and raspivid. All the settings can be tweaked in the source. Specifically, increase the --timeout delay for still images. I also want to experiment with the --exposure sports setting.
I still have more tweaking to do with the Pi Camera 2. If after a few more runs, I don't get the images I need, I'll try the HQ camera or try interfacing with an action camera.
Finally, I've added GPS functionality. If you access the application with your phone while you're riding, the application will associate your phone's GPS coordinates with each capture.
I have an old Canon S90 point and shoot camera that I haven't been using. This weekend, I thought I'd try to see if I could use it for this project.. It isn't rugged, but thought it might be fine for taking this project a bit further, as it takes great photos, and if I could find one, Canon did make a rugged waterproof case for it. It also has image stabilization, which should help with getting useable photos on my bumpy ride.
I looked at how I might be able to control it, and download photos for processing. First, I looked at PTP, the protocol for downloading images from cameras. PTP allows for telling the camera to take a picture, and then download it. I tried an PTP Node library, it didn't work, and then I tried using a command line PTP control tool called gphoto2. Gphoto2 worked great for downloading photos from the command line, but wouldn't instruct the camera to take a picture - it turns out, my S90 doesn't support that feature (although its predecessor, the S80, did!).
Then I thought, I could take regular pictures on a timer, and then download them for processing. I had done this before using CHDK custom firmware for Canon cameras. CHDK allows you to do all sorts of things with your camera that it can't do out of the box, including automation and scripting. I thought I would use a pre-written script to take a photo every 10 seconds, and then download it with gphoto2. But as soon as I connect the camera with PTP/gphoto2, the script stops. So I'm back to looking for a camera, or camera module, that I can control from a Pi & can take useable photos in a high-vibration environment.
We had an early snowfall here in Toronto, and I've put my bike into storage for the winter. I have given some thought about next steps though.
First, I found a really easy way to implement a display. I came across this article about a Vancouver cyclist who tries to "beat" the packed buses on along West Broadway with a display-equipped Pix Backpack. This backpack might be the quickest way to to implement a display.
Second, I started thinking about cameras. Looking at the footage from Cycliq cycling cameras, its definitely possible to get steady footage on a bicycle. I explored modules and spec sheets for various modules from Arducam and camera-modules.com - anything "fast" enough should take a suitable shot. And a co-worker suggested just using a GoPro, but the challenge is, how do you pull the image off to process it as you're riding? Reading various action camera reviews, I came across Yi Action cameras. Although none of the libraries seem to be current, they've made SDKs available to interface with their cameras: https://github.com/YITechnology/YIOpenAPI
I've reviewed the footage on Youtube from Yi cameras mounted to bicycles - it looks pretty good. I'll probably pursue this route.
I built an isolator with some wire and plywood, and mounted it along with the Pi to my bike:
I didn't tune it, I'll have to look into how to matching the springiness of the wire by tweaking the length against the weight of the Pi. But it wasn't enough - I think a faster camera is still required. Here are some sample photos from my bike, with the Pi mounted on the isolator:
Photo isn't clear enough to make the the writing on the green sign, or the plates on that car:
Photo is clear enough to make out objects that aren't in motion - Finch Ave., Soban cafe. But not the cars in motion.
I may try to "tune" the isolator, but I think either way, I need a better camera sensor.