QR Code detection
Regular barcodes:
- Linear ones or one-dimensional barcodes are series of lines of varying widths.
- Stores limited amount of information
- They can be only read by specialized barcode scanners
- Must be scanned from left to right
QR code:
- Two-dimensional bar code
- Grid of black and white squares
- Can be read by almost any smartphone or other device with a camera
- Can be read from any direction
Black and white squares in QR code:
- They represent binary data
- Each square is either black or white
- The position and arrangement of the squares are determined by a complex algorithm that ensures that the code can be read accurately even if the QR code is partially obscured or distorted.
Alignment patterns:
- These are the squares in the corners of a QR code
- Used to determine the orientation of the code
- Also used to correct any distortion that may have occurred
Applications of QR code:
- Mobile phone applications
- Websites
- Medical industry
Why QR code:
It contains error checking element that allows the code to be read even if it is damaged.
ways to read QR code:
- OpenCV (we used)
- hashlib
Steps for QR code detection:
1. install and load packages
!pip install opencv-python
import glob
import cv2
import pandas as pd
import pathlib
2. open and read QR code
read_qr_code() to read the QR code
cv2.imread() function to read the image
cv2.QRCodeDetector() class
detectAndDecode() function to extract data from the QR code
Working on bigdata:
- Create Pandas dataframe with two columns: filename, qr
- Load jpg files into directory and store in files
- Open, read, detect QR codes in thousands of images and store the outputs
File formats:
png, jpeg, pdf
References:
https://practicaldatascience.co.uk/data-science/how-to-read-qr-codes-in-python-using-opencv
Generate QR code:
Libraries: pillow, qrcode
Key points:
- Python QR Code image generator: qrcode
- Generate QR code image from the command line
- Generate QR code image with Python code
- QR code version of the generated image: version
- Error correction level: error_correction
- Cell size: box_size
- Margin width: border
- Color: fill_color, back_color
- Embed the QR code into the image
- Embed the image into the QR code
References:
Detect and read QR codes with OpenCV
Steps:
- cv2.QRCodeDetector
- Detect and read QR codes from an image
- Detect and read QR codes from camera video
References:
QR code validation:
1. Read QR Code from Image — Inverted Colour, Perspective Distortion, and Grayscale
https://www.dynamsoft.com/codepool/optimize-qr-recognition-performance.html
2. Locate QR code in large image to improve decoding performance
3. Read blurry barcode in python with pyzbar
https://stackoverflow.com/questions/64111254/read-blurry-barcode-in-python-with-pyzbar
4. Expire time of QR code
https://stackoverflow.com/questions/47598533/the-expire-time-of-qr-code
Furthermore: