Learn how to recognize the vehicle registration number from an image automatically with the CLI tool of Open ALPR in a Windows environment.

How to recognize a Vehicle registration plate from an image with Open ALPR (Automatic License Plate Recognition) in Windows

OpenALPR is an open source Automatic License Plate Recognition library written in C++ with bindings in C#, Java, Node.js, Go, and Python. The library analyzes images and video streams to identify license plates. The output is the text representation of any license plate characters recognized in the processed image. For our interest in this article is however only the CLI tool, that will make the interaction with the library easier without knowing what's the programming language that you need to use to operate with this tool. OpenALPR includes a command line utility, simply typing "alpr [image file path]" is enough to get started recognizing license plate images !

In this article, we'll explain you how to recognize a vehicle registration plate with this CLI tool in a Windows environment easily.

1. Download latest Open ALPR Release

As first step, you will need the executable (binaries) of the Open ALPR for Windows. Fortunately, you don't have to build them as you can easily download them from the Releases page of the project in Github here. After downloading the zip according to your architecture (x86 or x64), unzip its content in some directory, for example, as we'll add the path of the executable as an environment variable in Windows so we can simply type alpr instead of the entire path of the executable, we'll unzip it in the C:\Program Files\openalpr_64 directory.

Inside the folder you will find the alpr.exe file, that's the CLI utility that we'll use in this tutorial, so now is up to you to define the directory where the executable is located in the PATH of Windows (see this article to learn how to edit and set environment variables) or run the commands with the absolute path e.g:

"C:\\Program Files\\openalpr_64\\alpr.exe" "C:\\Program Files\\openalpr_64\\demo.jpg"

But, if you register the directory inside the path, the command will be easier to write:

alpr "C:\\Program Files\\openalpr_64\\demo.jpg"

Once you have the binary, proceed with the next step to learn how to use it. For more information about ALPR, please visit the official repository at Github here.

2. Using from the CLI

Now that you have the binary, you can either switch to the directory where the executable is located, that in our case is:

cd C:\Program Files\openalpr_64

Then, just run the command alpr providing as first argument the absolute/relative path to the image that you want to scan:

alpr ./demo.jpg

And that's it, alpr will start processing the given image and will print the results in the console:

ALPR Vehicle Registration Plate Recognition

Specify plate region

As you know, there are different kind of plates around the world, with different length and distribution, which means that in some cases alpr will need some help to identify correctly the identification. That's why you can specify the region code that alpr will use to identify correctly the identification of the plate, for example, if you try to identify another region style plate (an european plate with the default distribution of US), you will find the "No license plates found." message in the CLI, to prevent this, knowing the region of the plate, specify the code with the -c or --country flag with the value (which is us by default):

REM An european vehicle
alpr image.jpg --c eu

REM An american vehicle
alpr image.jpg --c us

See the following example:

Europa Vehicle Plate

Note

Although there is no code for every country in the world, you will need to specify the code. Normally, it should work for almost any plate with the us and eu code, however other valid values are: us, eu, au, auwide, gb, kr, mx, sg. For example, in the image of the article we are using a Colombian vehicle, however the us code worked to recognize it as it follows a similar pattern.

Generate output as JSON

If you are willing to parse the generated output from an application from your authority, for example an application written in some programming language like PHP, Node.js, Python etc. you can retrieve the information in a universal readable format like JSON, just add the --json flag to the command:

alpr image.jpg --json

And the CLI tool with output instead of the original text, a JSON structured object with the following structure:

{
  "version": 2,
  "data_type": "alpr_results",
  "epoch_time": 1546207403000,
  "img_width": 768,
  "img_height": 1024,
  "processing_time_ms": 33.806999,
  "regions_of_interest": [],
  "results": [
    {
      "plate": "KKV939",
      "confidence": 89.048828,
      "matches_template": 0,
      "plate_index": 0,
      "region": "",
      "region_confidence": 0,
      "processing_time_ms": 10.102,
      "requested_topn": 10,
      "coordinates": [
        {
          "x": 305,
          "y": 535
        },
        {
          "x": 481,
          "y": 533
        },
        {
          "x": 484,
          "y": 613
        },
        {
          "x": 308,
          "y": 616
        }
      ],
      "candidates": [
        {
          "plate": "KKV939",
          "confidence": 89.048828,
          "matches_template": 0
        },
        {
          "plate": "KKV9S9",
          "confidence": 80.908226,
          "matches_template": 0
        },
        {
          "plate": "KKV99",
          "confidence": 78.569084,
          "matches_template": 0
        },
        {
          "plate": "KXV939",
          "confidence": 75.373528,
          "matches_template": 0
        },
        {
          "plate": "KV939",
          "confidence": 74.683296,
          "matches_template": 0
        },
        {
          "plate": "KXV9S9",
          "confidence": 67.232918,
          "matches_template": 0
        },
        {
          "plate": "KV9S9",
          "confidence": 66.542694,
          "matches_template": 0
        },
        {
          "plate": "KXV99",
          "confidence": 64.893784,
          "matches_template": 0
        },
        {
          "plate": "KV99",
          "confidence": 64.203545,
          "matches_template": 0
        }
      ]
    }
  ]
}

Improvements to the OpenALPR library are always welcome. So please review the OpenALPR design description and get started. Code contributions are not the only way to help out. Do you have a large library of license plate images? If so, please upload your data to the anonymous FTP located at upload.openalpr.com. Do you have time to "tag" plate images in an input image or help in other ways? Please let everyone know by posting a note in the forum.

Happy coding !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors