With some free time on our hands, we equipped our beloved car with a Raspberry Pi, paired it with a camera, designed a client, and successfully created a real-time license plate detection and recognition system.
How can we create an intelligent car system without changing the car? For some time, the author Robert Lucian Chiriac has been thinking about how to give a car the ability to detect and recognize objects. This idea is intriguing because we have already witnessed the capabilities of Tesla, and while we cannot buy a Tesla right away (it must be mentioned that the Model 3 is looking increasingly attractive), he had an idea to work hard to achieve this dream.
Before starting, the first question that comes to my mind is what this system should be able to do.If there is one thing I have learned in my life, it is that taking things step by step is always the best strategy.
So, besides basic visual tasks, what I need is to clearly identify license plates while driving.This recognition process involves two steps:
-
Detect the license plate.
-
Recognize the text within each license plate bounding box.
-
A machine learning model that detects license plates from unlabeled images;
-
Some hardware.Simply put, I need a computer system connected to one or more cameras to run my model.
-
YOLOv3 – This is one of the fastest models available, and its mAP is comparable to other SOTA models.We use this model to detect objects;
-
CRAFT Text Detector – We use it to detect text in images;
-
CRNN – Simply put, it is a recurrent convolutional neural network model.It must be sequential data to arrange detected characters into words in the correct order;
-
First, the YOLOv3 model receives frames from the camera and finds the bounding boxes for the license plates in each frame.It is not recommended to use very precise predicted bounding boxes — it is better for the bounding box to be slightly larger than the actual detected object.If it is too tight, it may affect the performance of subsequent processes;
-
The text detector receives the cropped license plates from YOLOv3.If the bounding box is too small, it is likely that part of the license plate text is cut off, resulting in a poor prediction.However, when the bounding box is enlarged, we can allow the CRAFT model to detect the positions of the letters, making the position of each letter very accurate;
-
Finally, we can pass the bounding boxes of each word from CRAFT to the CRNN model to predict the actual words.
-
On the rearview mirror side, the Raspberry Pi + GPS module + 4G module will be retained.For the GPS and 4G antennas I used, you can check my article on the EC25-E module;
-
On the other side, I used an arm that utilizes a ball joint to support the Pi Camera.
Figures 1 and 2 show what they look like when rendered.Note that the c-shaped bracket here is pluggable, so the Raspberry Pi’s accessories and the support for the Pi Camera are not printed together with the bracket.They share a socket, with the bracket plugged into it.If any reader wants to replicate this project, this is very useful.
They only need to adjust the bracket on the rearview mirror.Currently, this base works very well in my car (Land Rover Freelander).
I found many pre-trained license plate models online, but not as many as I initially expected, although I did find one trained on 3600 license plate images.This training set is not large, but it is better than nothing.
Additionally, it was trained based on the pre-trained models from Darknet, so I could use it directly.
Model Address:
https://github.com/ThorPham/License-plate-detection
Dataset Address:
https://github.com/RobertLucian/license-plate-dataset
-
Keras Implementation:
https://github.com/experiencor/keras-yolo3
-
Submit Merge Request:
https://github.com/experiencor/keras-yolo3/pull/244
-
Perform all inference locally;
-
Perform inference in the cloud.
Cortex Project Address:
https://github.com/cortexlabs/cortex
Essentially, Cortex is a platform for deploying machine learning models as production web services.This means I can focus on my application while leaving the rest for Cortex to handle.
It does all the preparation work on AWS, and all I need to do is write a predictor using template models.Even better, I only need to write a few dozen lines of code for each model.
-
Define the cortex.yaml file, which is the configuration file for our API.Each API will handle one type of task.I assigned the task of detecting license plate bounding boxes on the given frame to the yolov3 API, while the crnn API predicts the license plate number with the help of the CRAFT text detector and CRNN;
-
Define the predictor for each API.Basically, what you need to do is define a predict method for a specific class in Cortex to receive a payload (all the servy part is already handled by the platform), which can predict the result and return the prediction.It’s that simple!
# predictor.pyimport boto3
import pickle
labels = ["setosa", "versicolor", "virginica"]
class PythonPredictor:
def __init__(self, config):
s3 = boto3.client("s3")
s3.download_file(config["bucket"], config["key"], "model.pkl")
self.model = pickle.load(open("model.pkl", "rb"))
def predict(self, payload):
measurements = [
payload["sepal_length"],
payload["sepal_width"],
payload["petal_length"],
payload["petal_width"],
]
label_id = self.model.predict([measurements])[0]
return labels[label_id]
curl http://***.amazonaws.com/iris-classifier \
-X POST -H "Content-Type: application/json" \
-d '{"sepal_length": 5.2, "sepal_width": 3.6, "petal_length": 1.4, "petal_width": 0.3}'
-
Collect frames at an acceptable resolution (800×450 or 480×270) at a frame rate of 30 FPS from the Pi Camera, and push each frame into a common queue;
-
In a separate process, I will take frames out of the queue and distribute them to multiple workstations on different threads;
-
Each worker thread (or what I call inference threads) will make API requests to my Cortex API.First, a request to my yolov3 API, and if any license plates are detected, another request will be sent with a batch of cropped license plates to my crnn API.The predicted license plate numbers will be returned in text format;
-
Each detected license plate (with or without recognized text) will be pushed to another queue, which will ultimately broadcast it to the browser page.At the same time, the predicted license plate numbers will be pushed to another queue to be saved to disk in CSV format later;
-
The broadcast queue will receive a set of unordered frames.The consumer’s task is to place them in a very small buffer (the size of a few frames) and broadcast a new frame to the client for reordering.This consumer runs separately in another process, and it must also try to keep the queue size fixed to a specified value to display frames at a consistent frame rate.Clearly, if the queue size decreases, then the frame rate will decrease proportionally, and vice versa;
-
Meanwhile, another thread will run in the main process, retrieving predictions and GPS data from another queue.When the client receives a termination signal, the predictions, GPS data, and time will also be saved to a CSV file.
One challenge I had to overcome was the bandwidth of 4G.It’s best to reduce the bandwidth required for this application to minimize possible hang-ups or excessive use of available data.
I decided to have the Pi Camera use a very low resolution:480×270 (we can use a small resolution here because the Pi Camera has a very narrow field of view, so we can still easily identify license plates).
-
Reduce the width to 416 pixels, which is the size required by the YOLOv3 model, and the scale is clearly intact;
-
Convert the image to grayscale;
-
Remove the top 45% of the image.The idea here is that the license plate will not appear at the top of the frame because cars do not fly, right?As far as I know, removing 45% of the image does not affect the performance of the predictor;
-
Convert the image to JPEG again, but at a much lower quality at this time.
The final frame size is about 7-10KB, which is excellent.This corresponds to 2.8Mb/s.However, considering all overheads like responses, it’s about 3.5Mb/s.
For the crnn API, cropped license plates do not require much space at all, even without compression, they are only about 2-3KB each.
Follow Replay Share Like Watch MoreJuly Online Lab
0/0
00:00/26:38
Progress Bar, 0%Play00:00/26:3826:38Fullscreen Playback speed 0.5x 0.75x 1.0x 1.5x 2.0x HD Smooth
Continue watching
You have a Tesla, I have a Raspberry Pi, DIY license plate recognition detection system, household car transforms into smart car
Reprinted, You have a Tesla, I have a Raspberry Pi, DIY license plate recognition detection system, household car transforms into smart carJuly Online LabAdded to Top StoriesEnter comment Video Details
The above is an example of real-time inference using Cortex.I need about 20 GPU-equipped instances to run it smoothly.Depending on the latency of this group of GPUs, you may need more GPUs or fewer instances.
The average latency from capturing a frame to broadcasting it to the browser window is about 0.9 seconds, considering that the inference occurs far away, it’s truly amazing — I’m still surprised.
Original Address:
https://towardsdatascience.com/i-built-a-diy-license-plate-reader-with-a-raspberry-pi-and-machine-learning-7e428d3c7401
Copyright Notice:This article content comes from the internet, copyright belongs to the original author, if there is any infringement, please contact for deletion.
[Today’s Recommendation: CV Employment Small Class Fourth Session]
Top Instructor Team
Six Major Practical Projects
Comprehensive Employment Services
1. Job Interview
Custom project for specific directions, final adjustments and improvements of the project and resume.Then arrange for major companies’ interviewers to simulate interviews and internal recommendations, iterating through interviews and feedback, ultimately helping students successfully obtain offers.
2. Employment Escort
For technical issues encountered in work after students are employed, a week of follow-up service will be provided to ensure stable employment for students.
Course Start Date
March 23


Click ↓↓“Read Original” to view course details!