Automatic License Plate Recognition Using Python And Open Cvs

  • Jul 30, 2017  License Plate Recognition using Python & OpenCV. Skip navigation. License Plate Recognition using Python & OpenCV. License plate recognition full source code and tutorial.
  • Comparing Faces Using Python and OpenCV? Terence Eden's Blog Papers that use OpenCV Computer Vision in Microassembly Workstation TOPOLOGICAL LOCALIZATION FOR MOBILE ROBOTS USING OMNI-DIRECTIONAL VISION AND LOCAL FEATURES Introduction to programming with OpenCV Building OpenCV from CVS.

In this article, we’ll look at a surprisingly simple way to get started with face recognition using Python and the open source library OpenCV. Before you ask any questions in the comments section: Do not skip the article and just try to run the code. Automatic License Plate Recognition API. Accurate, fast and easy to use API for license plate recognition. Trained on data from over 100 countries and regions around the world. The core of our license plate detection system is based on state of the art deep neural networks architectures. Integrate with our ALPR API in a few lines of code.

Active1 year, 2 months ago

I was wondering if anybody new of a way that I could use of scanning a registration plate on a car and then adding that number to a string inside java? I have been looking around a bit and came across this

But I'm not sure that it's exactly what I am looking for?

Anybody know of anything that might be of use? Thanks in advance!

Luke KavanaghLuke Kavanagh

1 Answer

Google has recently released Mobile Vision API for text recognition from images. You can take a picture from camera and then use this API to get your desired result. Link - https://developers.google.com/vision/text-overview

PassiondroidPassiondroid
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged javaandroidimage-processinganpr or ask your own question.

In this project you’re going to learn how to build a car recognition system using a Raspberry Pi and Node-RED. For this project we’ll be using a software called OpenALPR (Automatic License Place Recognition) that has an API you can use to identify car plates and car models based on an image.

Overview

This project is divided into two parts.

  1. First, we’ll identify a car using OpenALPR and Node-RED;
  2. Then, we’ll trigger an event based on the detected car (for example, open the garage when it detects that your car arrived home);

The following image shows how the detection process will work:

In this example, we use a PIR motion sensor to detect that the car arrives home. There are other sensors that may be more suitable to detect a car, for example:

  • Hall effect sensor: senses changes in magnetic field when the car is near;
  • Ultrasonic sensor: detects distance to an object;
  • Active infrared detectors: detects the presence of an object by detecting the reflection of infrared light.

Automatic License Plate Recognition Using Python And Open Cvs Caremark

When the sensor detects motion, the Raspberry Pi camera takes a photo. After that, the Pi sends a request to OpenALPR with the car photo to be identified. Then, the OpenALPR API returns the car details like: plate number, model, color, and the confidence of the results.

Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »

Learn Raspberry Pi, ESP8266, Arduino and Node-RED. This is a a step-by-step course to get you building a real world home automation system using open-source tools DOWNLOAD »

After identifying a car, we’ll do some verifications, and if we found an authorized car, we’ll trigger an event (that can be open the garage, for example). The following image contains a flowchart showing the process.

Here’s what happens: after the car has been identified by OpenALPR, we’ll check if the license plate and the car model match. If they match, we’ll check if the car is in the list of authorized vehicles. If it is, we’ll trigger an event. For example: open the garage. After that, we wait a determined period of time until the car enters the garage. Then, you need to add several verifications to check if the car has already entered the garage. If yes, you can close the garage.

Prerequisites:

  • You should be familiar with the Raspberry Pi – read Getting Started with Raspberry Pi.
  • You should have the Raspbian or Raspbian Lite operating system installed in your Raspberry Pi – read Installing Raspbian Lite, Enabling and Connecting with SSH.
  • We’ll be using the Raspberry Pi Camera V2 Module, we recommend reading: Guide to Raspberry Pi Camera V2 Module.
  • You need Node-RED installed on your Pi and Node-RED prepared to take photos with the Pi Camera

If you like home automation and you want to learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino, we recommend that you download our course: Build a Home Automation System for $100.

Parts Required

For this project you need the following parts (click the links below to find the best price at Maker Advisor):

  • Raspberry Pi Board – read Best Raspberry Pi Starter Kits
  • Mini PIR Motion Sensor or PIR Motion Sensor
  • Resistor (220 or 330 ohms should work)

Note: at the moment, we don’t have an automatic garage, so we’ll use an LED to mimic the event triggering (we know it is not the same thing, but you get the idea).

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Connect the Raspberry Pi Camera Module

With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following figure. Make sure the camera is connected in the right orientation with the ribbon blue letters facing up (you need to enable the camera in your Raspbian OS).

You should also have Node-RED installed in your Pi and the node-red-contrib-camerapi node Installed:

Schematics

Assemble the circuit to test this project. Follow these next schematic diagram:

After having your Raspberry Pi prepared and Node-RED software configured, you can continue with this project.

OpenALPR

OpenALPR is an open source Automatic License Plate Recognition library written in C++ with bindings in C#, Java, Node.js, Go, and Python. They also have the OpenALPR Cloud API which is a web service running in the cloud that analyzes images of vehicles and responds with license plate, model, color and much more. OpenALPR Cloud API has a free service that allows up to 2000 free recognitions per month.

Automatic License Plate Recognition Using Python And Open Cvs

Note: instead of using their Cloud API that is limited to only 2000 recognitions per month, you can install their Open Source software and use their Python integration to write Python scripts to analyse unlimited images. That way you don’t need to use their cloud service and you aren’t restricted to 2000 requests per month.

Supported countries

OpenALPR contains specialized training data for many plate styles. Currently, OpenALPR supports the following countries:

Note:Europe is not a country, but we assume that they support all countries in Europe. If your country is not listed, you may still experience high accuracy rates by using training data for a country that has plates that look similar to yours.

Creating a free account

To get started with OpenALPR Cloud API, you can create a free account. After completing your account creation, you should have access to the following page:

Open the Cloud API tab to access your Secret Key. You need it to make requests to the API.

Automatic License Plate Recognition Using Python And Open Cvs Hours

In my case, the secret key is: sk_8081041caedd50a———

Save your secret key in a safe place, because you’ll need it in just a moment.

Testing the Camera and OpenALPR Service

First, you should start by identifying your car using the Pi Camera and the OpenALPR service. So, start with the provided sample flow that takes a photo and makes a request to the OpeALPR Cloud API to identify your car. To import the Node-RED flow provided, go to the GitHub repository or click the figure below to see the raw file, and copy the code provided.

Next, in the Node-RED window, at the top right corner, select the menu, and go to Import > Clipboard.

Then, paste the code provided and click Import. The next nodes should show up in your flow:

Configuring the test flow

After importing the flow, you need to make some changes to make it work for you. Open the Take Photo node:

Edit the node to have the same settings as shown in the next figure:

  • File Name: car-photo.jpeg
  • File default path: No
  • File Path: /home/pi/Pictures/

Important: sometimes the previous node might overwrite the default setting. Make sure you double-check that it has the right settings. Then, click the deploy button.

Preparing your OpenALPR Cloud API request

Double-click the cURL POST node:

Then, change the Command field to include your Secret Key and country code:

By default, it should have this command:

Add your secret key that you’ve retrieved earlier and your country code:

Note:EU is not a country, but if you live in any country in Europe, you use the EU country code.

Automatic License Plate Recognition Using Python And Open Cvs Pharmacy

Copy and paste your exact command in the in the Command field of the cURL POST node and press the Deploy button in your Node-RED software for all the changes to take effect:

Testing the flow

After deploying the flow, let’s test the car identification process. Move your car to a place that you can take a photo with your Raspberry Pi:

Point the camera to the car and tap the square next to the timestamp node to trigger the flow.

That should take a photo with your Pi Camera, save it at /home/pi/Pictures/car-photo.jpeg and make a request to the cloud API to identify your car plate and model. It should print the JSON response in the Debug window.

Understanding the response

Open the debug window, and you should see an object with all the details about the JSON response. The results array should have at least one result (array[1]), otherwise it might be analyzing a photo without a car or it couldn’t identify the car (make sure the Pi Camera is pointed to the car while you take the photo).

Click the arrow next to the results: array[1] to expand the object. You should see a plate object with your car plate. Save the car plate in the format retrieved by the API. In my case it’s “61CP–“. You’ll need it later to identify your car:

Expand the vehicle object > make_model > 0: object and you should see the name of your car and how the API identified the car model. In our case it identified the car as a Toyota Yaris with 77,2% confidence. We should save the exact string “toyota_yaris” retrieved by the API, because we need it for the next flow. Save your car model in the format retrieved by the API.

Troubleshooting tips

In case your response returned invalid results, make sure you double check the following details:

  • The Take Photo node is storing the photo in the right file path: /home/pi/Pictures/
  • Make sure the camera is taking good photos (access the Raspberry Pi Pictures folder at /home/pi/Pictures/car-photo.jpeg to see if the photo taken looks good)
  • See if the photo has the car visible and the car plate, otherwise the API might not be able to identify the car properly
  • Make sure you’ve entered the right command with your own API key and country code in the cURL POST command

Car Plate Recognition System Flow

In this part, we’ll add the car detection and event triggering to our flow. When motion is detected, the Pi camera takes a photo with the Pi Camera and makes a request to OpenALPR. Then, based on the response, it will trigger an event (in this case we’ll set an output on to light up an LED).

To import the Node-RED flow provided, go to the GitHub repository or click the figure below to see the raw file, and copy the code provided.

Next, in the Node-RED window, at the top right corner, select the menu, and go to Import > Clipboard.

Then, paste the code provided and click Import. The next nodes should load in your flow:

Configuring the flow

After importing the flow, you need to make some changes to make it work for you. Open the Take Photo node:

Automatic License Plate Recognition Using Python And Open Cvs

Edit the node to have the same settings as shown in the next figure:

  • File Name: car-photo.jpeg
  • File default path: No
  • File Path: /home/pi/Pictures/

Automatic License Plate Recognition Using Python And Open Cvs Minute Clinic

Preparing your OpenALPR Cloud API request

Double-click the cURL POST node:

Automatic License Plate Recognition Using Python And Open Cvs

Then, change the Command field to include your Secret Key and country code:

By default, it should have this command:

Add your secret key that you’ve retrieved earlier and your country code:

Add your car details to the flow

Open the function node Identify Car to add your car’s license plate and model.

You need to replace the carPlate and carModel variables with your own car plate and model name (in the exact same format as retrieved earlier). In our case, we get:

The following figure shows the place where you should add your car plate and model on the function node:

Note: if you want to add another car plate, you need to edit the “Identify Car” function. Declare another carPlate2 and carModel2:

Then, after the else if statement, add the following:

That should allow you to verify two cars (you can add more).

Once you’ve added your car details, press Done and click the Deploy button:

Demonstration

Now, when the car arrives, the PIR sensor detects motion, the Pi Camera takes a photo, and the car is identified using the OpenALPR API.

Your Node-RED should identify your car plate and car model. Then, it will trigger an event: it turns GPIO 17 on for a few seconds and then it turns off. This simulates the open/close garage door command.

Wrapping Up

In this project we’ve shown you how to identify car plates using OpenALPR. We also show you how you can trigger an event based on a specific car plate. This way, you can automatically open your garage when you arrive with your car. You can modify this project to make it work for you and use it in your own home automation system.

In the example we’ve shown, we’ve used a PIR motion sensor to detect the car arriving. There are other sensors that might be better for this case like: ultrasonic sensor, active infrared sensor, or hall effect sensor, for example.

When we trigger the event, we wait 10 seconds until “closing the garage”. You need to add several verification processes (that we did not include in the flow) to check if the car has entered the garage or not.

We hope you’ve found this project interesting. If you like this project, you may also like:

Thanks for reading.