Skip to content

Instantly share code, notes, and snippets.

@wwwins
Created April 13, 2020 09:22
Show Gist options
  • Save wwwins/df982c1565c3f42acd1915b254a484d7 to your computer and use it in GitHub Desktop.
Save wwwins/df982c1565c3f42acd1915b254a484d7 to your computer and use it in GitHub Desktop.
Python QRCode decoder
# -*- 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