expqr/reader/__init__.py

40 lines
975 B
Python
Raw Normal View History

2020-10-08 17:58:47 +00:00
import zxing
import pyzbar.pyzbar
import PIL.Image
import PIL.ImageEnhance
import PIL.ImageFilter
import sys
import tempfile
class QRCode:
def __init__(self, content, rect):
self.content = content
self.rect = rect
2020-10-10 19:32:57 +00:00
def read_code(image):
2020-10-08 17:58:47 +00:00
reader = zxing.BarCodeReader()
codes = []
for _ in range(10):
2020-10-10 19:32:57 +00:00
tempimage = tempfile.NamedTemporaryFile(suffix=".png")
image.write(tempimage.name)
2020-10-08 17:58:47 +00:00
zxcontent = reader.decode(tempimage.name)
zbcontent = pyzbar.pyzbar.decode(PIL.Image.open(tempimage.name))
content = []
if zxcontent:
content.append(zxcontent.raw)
for single in zbcontent:
content.append(single.data.decode())
for code in content:
2020-10-10 19:32:57 +00:00
if code.startswith("EXP360:"):
return code
2020-10-08 17:58:47 +00:00
2020-10-10 19:32:57 +00:00
image.modulate(150, 100, 100)
image.contrast(150)
2020-10-08 17:58:47 +00:00
if __name__ == "__main__":
content = read_code(sys.argv[1])
print(content)