def _run_frame_worker(self, index, frame_queue, storage_queue, frame_callback): self.logger.debug('%s\tframe worker #%d - begin' % (self.tag_slug, index)) try: alpr = openalpr.Alpr( 'br', path.join(path.dirname(path.abspath(__file__)), 'config', 'openalpr.conf'), 'openalpr/runtime_data/') if not alpr.is_loaded(): raise Exception('Error loading OpenALPR') try: alpr.set_top_n(10) frame, when = frame_queue.get() while frame is not None: if frame_callback is not None: frame_callback(self, {'frame': frame, 'when': when}) for result in alpr.recognize_ndarray(frame)['results']: coords = result['coordinates'] x, y = [point['x'] for point in coords ], [point['y'] for point in coords] storage_queue.put({ 'info': { 'plate': result['plate'], 'confidence': result['confidence'], 'candidates': [{ 'plate': candidate['plate'], 'confidence': candidate['confidence'] } for candidate in result['candidates']], 'when': when, 'camera': { 'tag_slug': self.tag_slug, }, }, 'frame': frame, 'roi': frame[numpy.amin(y):numpy.amax(y), numpy.amin(x):numpy.amax(x), :], }) with self._processing_rate_lock: self._processing_counter += 1 frame_queue.task_done() frame, when = frame_queue.get() frame_queue.task_done() finally: alpr.unload() except: self.logger.exception('%s\tframe worker #%d - end by exception' % (self.tag_slug, index)) raise self.logger.debug('%s\tframe worker #%d - end' % (self.tag_slug, index))
from flask import jsonify, Flask, request import traceback import openalpr import sys _print = print def print(*args): _print(*args) sys.stdout.flush() ## Init OpenALPR alpr = openalpr.Alpr("us", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data") if not alpr.is_loaded(): print("Error loading OpenALPR") sys.exit(1) alpr.set_top_n(20) alpr.set_default_region("md") ## Init web Server app = Flask(__name__) @app.route('/recognize', methods=["POST"]) def image(): try:
import openalpr import os algorithm = openalpr.Alpr("eu", os.getenv("OPENALPR_CONFIG"), "/usr/share/openalpr/runtime_data/") algorithm.set_default_region("fi") algorithm.set_detect_region(True) def read_file(path): """Read plates from an image file Args: path (str): Path to an image file Returns: dict: Results from ALPR, with detected plates """ return algorithm.recognize_file(path) def read_array(array): """Read plates from a numpy array image Args: array (np.array): image data Returns: dict: Results from ALPR, with detected plates """ return algorithm.recognize_array(array)