mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 15:20:55 +08:00
Added OpenALPR Python bindings
This commit is contained in:
40
bindings/python/test.py
Normal file
40
bindings/python/test.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from openalpr import Alpr
|
||||
|
||||
|
||||
try:
|
||||
alpr = Alpr("us", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data")
|
||||
|
||||
if not alpr.is_loaded():
|
||||
print("Error loading OpenALPR")
|
||||
else:
|
||||
print("Using OpenALPR " + alpr.get_version())
|
||||
|
||||
alpr.set_top_n(7)
|
||||
alpr.set_default_region("wa")
|
||||
alpr.set_detect_region(False)
|
||||
jpeg_bytes = open("/storage/projects/alpr/samples/testing/car1.jpg", "rb").read()
|
||||
results = alpr.recognize_array(jpeg_bytes)
|
||||
|
||||
# Uncomment to see the full results structure
|
||||
# import pprint
|
||||
# pprint.pprint(results)
|
||||
|
||||
print("Image size: %dx%d" %(results['img_width'], results['img_height']))
|
||||
print("Processing Time: %f" % results['processing_time_ms'])
|
||||
|
||||
i = 0
|
||||
for plate in results['results']:
|
||||
i += 1
|
||||
print("Plate #%d" % i)
|
||||
print(" %12s %12s" % ("Plate", "Confidence"))
|
||||
for candidate in plate['candidates']:
|
||||
prefix = "-"
|
||||
if candidate['matches_template']:
|
||||
prefix = "*"
|
||||
|
||||
print(" %s %12s%12f" % (prefix, candidate['plate'], candidate['confidence']))
|
||||
|
||||
|
||||
|
||||
finally:
|
||||
alpr.unload()
|
Reference in New Issue
Block a user