-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenalpr_web.py
61 lines (42 loc) · 1.35 KB
/
openalpr_web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, jsonify, request
import json
import urllib
from base64 import b64encode
import requests
from openalpr import Alpr
import openalpr
import time
import json
app = Flask(__name__)
@app.route('/')
def hello_world():
return "hello world!"
@app.route('/alpr', methods = ['POST'])
def alpr():
start_time = time.time();
try:
print 'recieved image, processing...'
alpr = Alpr("us", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data")
alpr.set_top_n(20)
mid1_time = time.time();
if 'image' not in request.files:
print "image was not in files"
return 'Image parameter not provided'
jpeg_bytes = request.files['image'].read()
if len(jpeg_bytes) <= 0:
print "there are no bytes!"
return False
mid2_time = time.time();
results = alpr.recognize_array(jpeg_bytes)
print "got results!"
end_time = time.time();
print("total_time: " + str(end_time-start_time));
print("alpr_time: " + str(mid1_time-start_time));
print("jpeg_time: " + str(mid2_time-mid1_time));
print("processing_time: " + str(end_time-mid2_time));
return jsonify(results)
except Exception, e:
print e
raise e
if __name__ == "__main__":
app.run(debug = True)