QR Code Scanner in Python
This article is to introduce the Python library known as qrtools, which can be used to scan and generate QR code in Python.
What is QR Code?
A QR code is a readable barcode. The ISO standards 18004 are used to set down a QR code. They are being set as standard throughout the world. The only difference between 2 QR codes will be the number of modules to store the data. An array of 21×21 elements is known as QR code. the size of an array can be increased by 4can be increased by 4 modules for each increase in version number.
QR bar code stores the information per unit area, being a 2-dimensional barcode.
Generate a QR code using
qrtools consists of a class QR, for which we must create an object in the beginning. This particular object takes certain arguments which are as follows:
- data_type
- margin_size
- data
- level
- pixel_size
To create a qrcode we run the following codes:
from qrtools import QR first_QR = QR(data = u"Example") first_QR.encode() #When the program runs successfully, the QR is stored in a tmp_folder. #To access the QR code image print(first_QR.filename)
Output:
/tmp/qr-1496334996.385343/7489ebbcc2a00056ddaaaac190bce473e5c03696ea1bd8ed83cf59a174283862.png
You may read: Generating QR-Codes in Python using QRCode Library
Read a QR code
The reading and scanning of a QR code is comparatively simple. While reading the QR object, we must specify the path of our QR code as an argument.
For example, to decode the QR code created at the beginning, we must run the following code.
from qrtools import QR first_QR = QR(filename = "home/user/Desktop/qr.png") first_QR.decode() print(first_QR.data)
Also read,
Leave a Reply