Install Openalpr in Windows python

喜夏-厌秋 提交于 2019-12-12 08:49:03

问题


I am using Windows 10 and I want to install openalpr and import the library to python.

However, after downloaded the Pre-compiled Windows binaries, I dont know how ti import alpr in python

I follow the instruction in OpenAlpr

I downloaded the openalpr-2.3.0-win-64bit.zip here and unzipped it.

Afterwards, I can run alpr in command line but I cannot import it.

Can anyone teach me how I can import Openalpr in python. Thank you.


回答1:


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




回答2:


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



回答3:


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().



来源:https://stackoverflow.com/questions/39092992/install-openalpr-in-windows-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!