40 lines
No EOL
975 B
Python
40 lines
No EOL
975 B
Python
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
|
|
|
|
def read_code(image):
|
|
reader = zxing.BarCodeReader()
|
|
codes = []
|
|
|
|
for _ in range(10):
|
|
tempimage = tempfile.NamedTemporaryFile(suffix=".png")
|
|
image.write(tempimage.name)
|
|
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:
|
|
if code.startswith("EXP360:"):
|
|
return code
|
|
|
|
image.modulate(150, 100, 100)
|
|
image.contrast(150)
|
|
|
|
if __name__ == "__main__":
|
|
content = read_code(sys.argv[1])
|
|
print(content) |