I installed OpenALPR itself fine and I was able to run it in terminal to get this result:
C:\Users\zebsu>"C:\\OpenALPR\\Agent\\bin\\alpr.exe" "C:\\plate.jpg"
plate0: 3 results
State ID: us-oh (97% confidence)
- PZ65BYV confidence: 94.5181 pattern_match: 0
- P265BYV confidence: 81.1941 pattern_match: 0
- P65BYV confidence: 81.1336 pattern_match: 0
However, I then followed the instructions found on PyPI (https://pypi.org/project/openalpr/#description) to install the openalpr python bindings with pip install openalpr
. But when I run the following code that they suggest with python 3.8.6 x64:
import json
from openalpr import Alpr
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
sys.exit(1)
results = alpr.recognize_file("C:/image.jpg")
print(json.dumps(results, indent=4))
alpr.unload()
I get the following error:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libopenalpr.dll' (or one of its dependencies). Try using the full path with constructor syntax.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
And this is the error that I get if I run the code with python 3.6.8 x32:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
I've scoured all the internet forums looking for answers however most of the submissions are from years back before the openalpr bindings could be installed with pip and had to be installed from github. Does anyone have any advice?
I ended up finding the solution from the answer to a question on another thread with a similar error but with a different library: FileNotFoundError: Could not find module 'libvlc.dll'. The issue was that the program had no way to find the dll files it needed so the directory where the dll files are needs to be added to the os in the python code. For me this meant adding these lines to the top of my code:
This change meant that the code ran exactly as it was supposed to.