forked from openalpr/openalpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenalpr_web.py
More file actions
38 lines (30 loc) · 1.05 KB
/
openalpr_web.py
File metadata and controls
38 lines (30 loc) · 1.05 KB
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
from openalpr import Alpr
import json
import tornado.ioloop
import tornado.web
import os
alpr = Alpr("eu", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data")
alpr.set_top_n(10)
alpr.set_default_region("de")
alpr.set_detect_region(False)
class MainHandler(tornado.web.RequestHandler):
def post(self):
print("start", flush=True)
if 'image' not in self.request.files:
self.finish('Image parameter not provided')
fileinfo = self.request.files['image'][0]
jpeg_bytes = fileinfo['body']
if len(jpeg_bytes) <= 0:
return False
print("analyzing " + fileinfo.filename, flush=True)
results = alpr.recognize_array(jpeg_bytes)
if "plate" in json.dumps(results):
print("plate found: " + results["results"][0]["plate"])
print("end", flush=True)
self.finish(json.dumps(results))
application = tornado.web.Application([
(r"/alpr", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.current().start()