Install Openalpr in Windows python

When you've downloaded the binary distribution, navigate to python subdirectory and run python setup.py. This would install OpenALPR as package, so then you would be able to import it from anywhere, not just from ALPR's directory.

Explaination: To be importable, it requires that the package you're trying to import been else:

  1. In current directory, from where you run python
  2. Specified via PYTHONPATH environment variable
  3. Part of standard library
  4. Specified in one of .pth files
  5. Located in site-packages dir
  6. Added to sys.path by hand

And when you run setup.py script, it kicks distutils to properly copy package's distribution to site-packages, thus adding it to your libs.

For more information, see setup.py usage and how import system works


I setted up the same environment as you:

  • Anaconda 4.0 installed into C:\Users\user\Anaconda
  • OpenAlpr installed into C:\Users\user\Downloads\openalpr-2.3.0-win-64bit

So I can call python from the console (cmd) and get:

Python 2.7.11 |Anaconda 4.0.0 (64-bit)
...

The module

As the bindings are not shipped with the pre-compiled Windows binaries, you have to install the module manually:

  • download the GitHub repo as ZIP;
  • extract the archive to a temporary folder, let's say C:\Users\user\Downloads\openalpr-master;
  • Python binding is into the C:\Users\user\Downloads\openalpr-master\src\bindings\python folder;
  • open a console into this directory and type python setup.py install

Voilà, the Python module OpenAlpr is installed!.

Call python_test.bat from the OpenAlpr directory to see it works.


Usage

To be able to import OpenAlpr module from Python, two solutions.

Solution 1: you will need to work into the OpenAlpr directory where DLL files are located. Then, it should works as expected:

>>> from openalpr import Alpr
>>> alpr = Alpr('us', 'openalpr.conf', 'runtime_data')
>>> alpr.is_loaded()
True

Solution 2 (best I think): you update the PATH to include the OpenAlpr folder:

>>> from os import environ
>>> alpr_dir ='C:\Users\user\Downloads\openalpr-2.3.0-win-64bit\openalpr_64'
>>> environ['PATH'] = alpr_dir + ';' + environ['PATH']

>>> from openalpr import Alpr
>>> alpr = Alpr('us', alpr_dir + '/openalpr.conf', alpr_dir + '/runtime_data')
>>> alpr.is_loaded()
True

It looks like you need to add the OpenALPR to the system path (step 4 below) and install the Python bindings (step 5 below). This is how I got OpenALPR to work on Windows 7/Anaconda 3/python 3.5 x64:

  1. You should uninstall any previous version of ALPR

  2. Download the binaries and the source code from https://github.com/openalpr/openalpr/releases

  3. Unzip the binaries and the source code in some directory, for example C:\OpenALPR

  4. Add the directory where alpr is located to your PATH. In my case C:\OpenALPR\openalpr_64

  5. Use Anaconda Prompt to install the Python bindings (they are in the source code directory). In my case:

cd C:\OpenALPR\openalpr-2.3.0\src\bindings\python
python setup.py install --record files.txt
  1. Test your installation in the same prompt:
cd C:\OpenALPR\openalpr_64
python_test.bat

Output:

Using OpenALPR 2.3.0
Image size: 497x372
Processing Time: 22.618999
Plate #1
          Plate   Confidence
  -       THECAR   92.207481
  -       THEGAR   81.348961
  -        HECAR   80.229317
  -       TMECAR   78.159492
  -       THE0AR   77.702461
  -       THECAB   77.389000
  -        THEAR   76.510017

Now there is a problem with the unload method of the DLL, but that is another issue: Exception ignored in: <bound method Alpr.__del__ of <openalpr.openalpr.Alpr object at 0x0000000002C04198>>. BTW this problem only happen when using alpr.unload().