Code/Decode QR Codes

Introduction

A QR code is a type of two-dimensional matrix barcode, invented in 1994, by Japanese company Denso Wave for labeling automobile parts. (Wikipedia)

Project #1

Send a friend a message in a QR code image file. Have them decode and read it.

See: How To Decode A QR Code In Python

Project #2

How do you read (decode) a QR code on a commercial product or service or screen?

Code Example

#!/usr/bin/python3 # ============================================================== # Encode/Decode QR code in Python # ============================================================== # pip install qrcode # pip install opencv-python # ============================================================== import qrcode import cv2 text = 'Happy Birthday!' qrcode_file = 'qrcode_test.png' # ---- encode -------------------------------------------------- qr = qrcode.QRCode(version = 1, box_size = 10, border = 5) qr.add_data(text) qr.make(fit = True) img = qr.make_image(fill_color = 'red', back_color = 'white') img.save(qrcode_file) print() print(f'Saved QR code in file {qrcode_file}') # ---- decode --------------------------------------------------- qrcode_file = 'qrcode_test.png' detector = cv2.QRCodeDetector() qrtext,_,_ = detector.detectAndDecode(cv2.imread(qrcode_file)) print() print(qrtext)