简体   繁体   中英

AttributeError: 'Alpr' object has no attribute 'loaded'

First I downloaded OpenALPR src and binary from here: Release ( src & binary )

Extracted src and binary in C:\\OpenALPR, afterwards I added C:\\OpenALPIR\\openalpr_64 to my path (Enviroment Variables -> Path -> Edit -> New) and then I ran follownig commands from src/bindings/python

c:\OpenALPR\openalpr-2.3.0\src\bindings\python>python setup.py build
running build
running build_py
creating build
creating build\lib
creating build\lib\openalpr
copying openalpr\openalpr.py -> build\lib\openalpr
copying openalpr\__init__.py -> build\lib\openalpr

c:\OpenALPR\openalpr-2.3.0\src\bindings\python>python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing C:\Users\Danial\AppData\Local\Programs\Python\Python36\Lib\site-packages\openalpr-1.0-py3.6.egg-info
Writing C:\Users\Danial\AppData\Local\Programs\Python\Python36\Lib\site-packages\openalpr-1.0-py3.6.egg-info

After that I changed my dir to the directory where alpr is located.

c:\OpenALPR\openalpr-2.3.0\src\bindings\python>cd c:\OpenALPR\openalpr_64

And I ran python_test.bat

c:\OpenALPR\openalpr_64>python_test.bat
Traceback (most recent call last):
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\lib\site-packages\openalpr\openalpr.py", line 51, in __init__
    self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalprpy.dll")
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\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 "python/test.py", line 21, in <module>
    alpr = Alpr(options.country, options.config, options.runtime_data)
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\lib\site-packages\openalpr\openalpr.py", line 61, 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.
Exception ignored in: <bound method Alpr.__del__ of <openalpr.openalpr.Alpr object at 0x000001D89B9B2D68>>
Traceback (most recent call last):
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\lib\site-packages\openalpr\openalpr.py", line 258, in __del__
  File "C:\Users\Danial\AppData\Local\Programs\Python\Python36\lib\site-packages\openalpr\openalpr.py", line 135, in is_loaded
AttributeError: 'Alpr' object has no attribute 'loaded'
Press any key to continue . . .

But if I run test.py from src folder ie:

C:\OpenALPR\openalpr-2.3.0\src\bindings\python>python test.py -c us --config "c:\OpenALPR\openalpr_64\openalpr.conf" --runtime_data "c:\OpenALPR\openalpr_64\runtime_data" c:\OpenALPR\openalpr_64\samples\us-1.jpg
Using OpenALPR 2.3.0
Image size: 497x372
Processing Time: 1258.149048
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

The error is due to openalprpy.dll I copied openalprpy.dll from binary folder and pasted in Python\\Python36\\Lib\\site-packages\\openalpr this has fixed the problem but I think its not intended?

Thanks a lot for the hint with copying the openalprpy.dll. However, I am on Linux and the fix here is slightly different.

I think i messed it up because i previously had openalpr installed via pip, which installs version 1.1.0. Then I uninstalled openalpr via pip und installed it from openalpr/src/bindings/python/ with python setup.py install , but somehow i was still getting the AttributeError: 'Alpr' object has no attribute 'loaded' .

Thanks to OP here I copied the libopenalprpy.so (the Linux-equivalent of openalprpy.dll ) from openalpr/src/bindings/python/ to /usr/lib/ , which overrode a file with the same name which probably was still there from the erroneous openalpr 1.1.0 installation. You need sudo privileges to do that btw. Afterwards I could use the python bindings just as OP.

This was done with Ubuntu 18.04 on a Jetson Nano.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM