mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 07:20:50 +08:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
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() |