Created
April 13, 2020 09:22
-
-
Save wwwins/df982c1565c3f42acd1915b254a484d7 to your computer and use it in GitHub Desktop.
Python QRCode decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright 2020 isobar. All Rights Reserved. | |
# | |
# Usage: | |
# python qrdecoder.py img.jpg | |
# | |
import os | |
import sys | |
import json | |
import argparse | |
from pyzbar.pyzbar import decode, ZBarSymbol | |
from PIL import Image | |
parser = argparse.ArgumentParser(description='QRCode decoder') | |
parser.add_argument('file', help='image file') | |
args = parser.parse_args() | |
def dec(imgdata): | |
qr_dic = {} | |
for data in imgdata: | |
x = data[2][0] | |
qr_dic[x] = data[0].decode('UTF-8') | |
for qr in sorted(qr_dic.keys()): | |
print('>>>',qr_dic[qr]) | |
if __name__ == "__main__": | |
print("Processing:",args.file) | |
r = decode(Image.open(args.file), symbols=[ZBarSymbol.QRCODE]) | |
dec(r) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment