【问题标题】:Error when trying to run OpenALPR in python尝试在 python 中运行 OpenALPR 时出错
【发布时间】:2020-10-02 21:30:07
【问题描述】:

我很好地安装了 OpenALPR,并且能够在终端中运行它来获得这个结果:

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

但是,我随后按照 PyPI (https://pypi.org/project/openalpr/#description) 上的说明安装带有 pip install openalpr 的 openalpr python 绑定。但是当我使用 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()

我收到以下错误:

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.

如果我使用 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.

我搜索了所有互联网论坛以寻找答案,但是大多数提交的内容都是几年前的,在 openalpr 绑定可以使用 pip 安装并且必须从 github 安装之前。有人有什么建议吗?

【问题讨论】:

    标签: python openalpr


    【解决方案1】:

    我最终从另一个线程上的问题的答案中找到了解决方案,该线程具有类似的错误但使用不同的库:FileNotFoundError: Could not find module 'libvlc.dll'。问题是程序无法找到它需要的dll文件,因此需要将dll文件所在的目录添加到python代码中的os中。对我来说,这意味着将这些行添加到我的代码顶部:

    import os
    os.add_dll_directory("C:/OpenALPR/Agent/bin")
    

    此更改意味着代码完全按照预期运行。

    【讨论】:

      猜你喜欢
      • 2020-06-14
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-17
      • 2021-10-15
      相关资源
      最近更新 更多