-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqrreader.py
More file actions
31 lines (28 loc) · 886 Bytes
/
qrreader.py
File metadata and controls
31 lines (28 loc) · 886 Bytes
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
import os
import zbar
import Image
from flask import jsonify
class QRReader:
def __init__(self, fname):
sc = zbar.ImageScanner()
pil = Image.open(fname).convert("L")
raw = pil.tobytes()
w,h = pil.size
self.img = zbar.Image(w,h,'Y800', raw)
sc.scan(self.img)
def __str__(self):
cev = "<htm><pre>"
for s in self.img:
t = ""
for x,y in s.location:
t += "(%d, %d) " % (x,y)
cev += t + " : " + s.data + " \n"
return cev + "</pre></html>"
def json(self):
res = {}
i = 0
for s in self.img:
res[i] = {"data": s.data, "location": (s.location[0], s.location[2]),
"count": s.count, "quality": s.quality, "type": "%s" % s.type, }
i += 1
return jsonify(res)