-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhascodes.py
More file actions
61 lines (56 loc) · 1.53 KB
/
hascodes.py
File metadata and controls
61 lines (56 loc) · 1.53 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import zbar
from PIL import Image
import cv2
import math
import hascodes
def distance(a,b):
return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
def getArea(points):
pts = [ [a,b] for a,b in points]
sides=[ distance(pts[i%4],pts[(i+1)%4]) for i in xrange(4) ]
print sides, pts
class GetCodes:
hasQR = False
hasBar = False
others = False
qr = []
bar = []
gray = None
area = None
def clear(self):
self.hasQR = False
self.hasBar = False
self.others = False
self.qr = []
self.bar = []
self.gray = None
self.area = None
def __init__(self):
self.hasQR = False
self.hasBar = False
self.others = False
self.qr = []
self.bar = []
self.gray = None
self.area = None
def scan(self, gray):
self.gray = gray
image = Image.fromarray(gray)
width, height = image.size
zbar_image = zbar.Image(width, height, 'Y800', image.tobytes())
scanner = zbar.ImageScanner()
scanner.scan(zbar_image)
cnt=0
for decoded in zbar_image:
cnt+=1
if decoded.type is zbar.Symbol.EAN13:
self.hasBar=True
self.bar.append(decoded)
elif decoded.type is zbar.Symbol.QRCODE:
self.hasQR=True
self.qr.append(decoded)
self.area = getArea(decoded.location)
else:
self.others=True
print cnt