License Plate Detection for Precise Car Distance Estimation

Introduction

When it comes to advanced driver-assistance systems or self-driving cars, one needs to find a way of estimating the distance to other vehicles on the road. One creative approach to achieve this goal would be to detect license plates in the real-time footage recorded by the cameras installed in a car. The standardized size of license plates enables us to compute the distance to the car in front by doing some computations using the detected bounding box. Besides, this information can help to better differentiate cars from other vehicles and objects on the road.

In this blog post, resulting from joint work with Aigiz Kunafin (TIMETOACT GROUP Austria Data Science), we try to build an algorithm as sketched above and fine-tune it to achieve decent performance.

Final license plate detection as well as derived and true distance

Detecting license plates

At the beginning of every data science project is the need for appropriate data. For our purposes we need images of cars with license plates of equal size and look. Together with these images we require information about the position of plates in the image as well as the real distance from the camera to the car. 

Once we have collected this data, we need an algorithm capable of detecting objects in an image reliably and in real-time. For this purpose, the YOLOv5 architecture is one of the most popular choices as it is highly performant while being extremely small [1]. Based on the machine learning framework PyTorch, there are five different pre-trained models balancing the trade-off between high accuracy and fast detection times. As we want fast predictions and reasonable accuracy, we chose the medium sized model balancing both requirements.

Having found an appropriate pre-trained model for object detection, we want to fine tune it to detect license plates in the next step. By applying data augmentation, i.e. altering the training images for every training batch, we can extend our existing data and enable our model to generalize better (check sample images below). Note that the existing images are not only randomly flipped and tilted but also cut and combined with other images. As the training images are different in every training step, the model is forced to actually learn the concept of a license plate in different scenarios. This reduces the risk of overfitting to the training images.

Training batch samples demonstrating data augmentation

Doing the math

Computing the distance

Once we have a reliable and accurate model at hand its predictions provide us with information about the width of the found license plate in pixels (W_pixel). Knowing the real width (W_real) of a license plate, which is 52 cm, and applying triangle similarity we can derive the distance of the car to the camera (D):

The only part missing is focal length (F). This factor can, however, be extracted from the technical metadata saved in the jpg files. As we have to correct some variables of the data a few more computational adaptations are necessary (check out details here [2]). 

Angle correction refinement

So far, our model is only capable of detecting bounding boxes parallel to the image boundaries. This can be problematic as license plates are not necessarily horizontally aligned. Besides the width of a license plate also its height is standardized. We can hence utilize the information about this constant ratio and correct for the fact that a bounding box of a tilted license plate will have a larger height. In the image below, for example, the license plate width used for our calculations (W_real) gets corrected. Instead of the real width of 52 cm the calculations yield that we should use a width of 51,88 cm. This compensates the tilt, which would otherwise cause our predicted bounding box width to be too small and thus lead to an overestimation of the distance.

Putting it all together

Finally, we can combine detection and computations to estimate the distance.

The graphs below show the quality of different versions of the model by comparing the predicted distance with the true distance of the test data. The mean relative error (MRE) provides insight into the average deviation from the true distance while the mean squared error (MSE) particularly penalizes large mistakes. This means, we aim at achieving low values in both cases. Besides, we can compare the approaches based on how many of the test images have a deviation of at most 5% of the true distance. This metric should thus be as high as possible.

True annotations: For this model, we do not use object detection for detecting license plates, but rather combine the true license plate width in the image with the distance computation. By using these “true” positions we try to set a baseline of what could be achieved in the best case by our computations. The reason for this being not at 100% lies in several possible biases, like imprecise focal lengths, true annotations and distance measures in our data. Unfortunately, testing has shown that the angle refinement led to almost no improvement in this setting

Simple model: This model uses an object detection model where the training data has not been augmented. Compared to the baseline, the simple model already performs quite well but there is room for improvement.

Best model: An extension of the simple model where the object detection model has been trained with augmented data. For this model, the metrics improve noticeably. As the pre-assessment already suggested, the angle correction does not lead to the expected improvement. However, inspection of our predictions showed that we systematically underestimate the distance. This might be caused by a slight bias in our focal length computation. Correcting for this factor leads to another major improvement. Applying the final model, we can predict the distance to a car in front in 85% of the cases right with 5% tolerance.

Additionally, the best model trained detects license plates in almost all test images (except for one). While the simple model was unable to detect anything in six out of 72 test images (cf. technical appendix). This can be attributed to higher generalization power due to data augmentation, which is particularly important for real-world deployment.

Conclusion

In summary, we were able to build a powerful algorithm to estimate the distance to a car in front based on images and by utilizing the standard dimensions of a license plate. Using the fast YOLOv5 model, we would be able to operate in real-time with great accuracy. Testing on the validation set for a range of around 1 to 8.5 meters showed that we can estimate the distance correctly within a small tolerance in 85% of the cases. Moreover, we are on average only 3,5% off the true distance.

This algorithm could thus be an effective and efficient solution instead of ultrasonic sensors, as cameras and powerful computers are usually already built into cars for other advanced driver-assistance systems. Making use of additional cameras installed in a car, accuracy of the distance estimation could be increased further as this would allow to combine positional information from different angles. Additionally, utilizing the detected license plates can help to differentiate between cars and other objects on the road with higher certainty. After all, looking at the current capabilities of this algorithm from a broader perspective, numerous further applications can emerge.

[1] Cf. GitHub - ultralytics/yolov5: YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite , YOLOv5 is Here!

[2] OpenCV: How-to calculate distance between camera and object using image?

 

Technical appendix

Collected numerical results (to achieve full comparability, best model and the true annotation approach were evaluated on the images where also the simple model detected license plates).

Training process of the final model. The two left images show the decrease in box and object loss for the train set, the images to the right for the test set after each training epoche.

Referenz

New license strategy for CG Car-Garantie

CarGarantie optimised its Atlassian licensing with catworkx – for greater cost efficiency and flexibility in its growing IT infrastructure.

Kompetenz

New Work & Agile Organization

When it comes to New Work and Agile Organization, we are not interested in achieving utopias, but in real, sustainable change that advances your business just as much as your employees.

Referenz 10/4/21

Support for IBM software licenses and ILMT for GLS

TIMETOACT not only takes over the support of the ILMT for GLS IT Service GmbH and assists with the compliance of license requirements, but also advises in the future on questions regarding licensing and license acquisition.

Headerbild zu Lizenzanalyse und Lizenzberatung.
Service

License analysis and license consulting

Only well-founded information can serve as a basis for meaningful decisions or budgeting. Therefore, we are happy to offer you an inventory of your licenses and our experts will also analyze your infrastructure.

Referenz 8/22/23

Managed service support for optimal license management

To ensure software compliance, TIMETOACT supports FUNKE Mediengruppe with a SAM Managed Service for Microsoft, Adobe, Oracle and IBM.

Lizenzoptimierung
Technologie

License Optimization

With our License Consulting we help you to determine the actual demand and to carry out a RightSizing in coordination with you. .

Service 9/12/22

Licenses & Apps

Unrivalled fast licensing service incl. optimization for all Atlassian and Marketplace products

Headerbild von Enterprise Service Management
Service

Enterprise Service Management

Our Enterprise Service Management Solution offers you a way to make Service Management accessible to all participants via an easy-to-use service portal. You can map your processes in this portal according to defined procedures and connect them to other systems. In addition, you relieve the process participants through automation.

IBM Software Lizenzen, Maintenance und Lizenzmanagement
Kompetenz 8/24/21

Software licenses, maintenance and license management

You can purchase your software licenses through us. We will gladly and competently advise you on your software licenses and maintenance.

Referenz 11/3/21

Mix of IASP & ILMT support for optimal license management

To minimize financial risk and personnel time, UTA resorts to proactive management of the license inventory (IASP) by TIMETOACT. In this way, not only will IBM license audits be avoided in the future, but TIMETOACT will also ensure compliance-compliant use of the ILMT as part of license management.

Teaserbild zu Lizenz- und Vertragsoptimierung.
Service

License and contract optimization

Based on the license analysis, we check the feasibility of potential savings from both a technological and commercial point of view.

Referenz 6/1/21

Continuous license support pays off

If IBM software is used, the compliance-conforming use of the IBM License Metric Tool (ILMT) plays a decisive role. TIMETOACT ensures compliance with IBM regulations for a city administration in North Rhine-Westphalia and continuously monitors the correct licensing.

Offering 8/8/22

Atlassian Enterprise License Agreement (ELA)

Designed specifically for large enterprises and corporations, ELA includes all Atlassian products.

Headerbild IBM License Metric Tool (ILMT)
Technologie

IBM License Metric Tool (ILMT)

The IBM License Metric Tool (ILMT) is provided free of charge by IBM to ensure monitoring of IBM software in virtualized environments.

Referenz

Cost reduction through centralized license management

With the support of catworkx, adesso implemented the “Atlassian-as-a-Service” (SaaS) model, which combines all licenses under one license key and manages them via the central IT.

Checkliste als Symbol für die verschiedenen To Dos im Bereich Lizenzmanagement
Blog 2/1/22

License Management – Everything you need to know

License management is not only relevant in terms of compliance but can also minimize costs and risks. Read more in the article.

CLOUDPILOTS Blog
Offering

Google for Education

The digital classroom for the home

News 5/23/24

HCL license and price adjustments as of 8.8.2024

HCL Software has informed us that the license and maintenance prices for the various product categories will be increased as of 8.8.2024.

Referenz 3/30/22

License and software consulting from a single source

TIMETOACT has been supporting the sports retailer for more than two years, not only for the support of the ILMT, but also for consulting on IBM Cognos - which was part of the IBM audit, among other things.

Produkt

Software for Idea and Innovation Management for SAP

Unique software for idea and innovation management based on SAP technology; for SAP HCM and SuccessFactors; using Fiori apps

Bleiben Sie mit dem TIMETOACT GROUP Newsletter auf dem Laufenden!