What are QR codes?
A Quick Response (QR) code is a 2 dimensional barcode that is used due to its fast readability and relatively large storage capacity. 2 dimensional barcodes are similar to one dimensional barcodes, but can store more information per unit area.
Installation and Dependencies
Linux: qrtools can be installed on debian based linux systems with the following commands
Generating a qrCode:
qrtools contains a class QR (can be viewed in the source code), for which we must initially create an object. The object takes the following arguments
data
pixel_size
level
margin_size
data_type
To create a QR code with default settings, we must simply specify the data while creating the object. Note that the data must be a unicode object if non-ASCII objects are going to be used.
If the program runs successfully, it returns a value of 0, and the QR code is stored in the tmp folder. To know the exact location, use the following command
The pixel value of the QR code may also be changed by specifying the value during the creation of the QR object. The default size tends to be a little small for reading using scanners on smartphones, so a size of around 10 would be ideal for such purposes,
Reading a QR code:
Scanning and reading a QR code is relatively simple. While creating the QR object, we must simply specify the path to the QR code as an argument. Suppose we are trying to decode the QR code created at the beginning of the article.
We may also print the values of the other parameters passed while creating the QR object to generate the QR code.
Please write comments if you find anything incorrect, or you want to know more information.Please share if you like this post .Thank you
A Quick Response (QR) code is a 2 dimensional barcode that is used due to its fast readability and relatively large storage capacity. 2 dimensional barcodes are similar to one dimensional barcodes, but can store more information per unit area.
Installation and Dependencies
Linux: qrtools can be installed on debian based linux systems with the following commands
$sudo apt-get update
$sudo apt-get install python-qrtools
The following dependencies must be installed as well$sudo apt-get install python-qrtools
[sudo] pip install pypng
[sudo] pip install zbar
[sudo] pip install pillow
Windows: qrtools can be installed on windows by downloading the file from here(https://pypi.python.org/pypi/qrtools/0.0.1). On downloading and extraction, run the following command from inside the folder[sudo] pip install zbar
[sudo] pip install pillow
python setup.py install
Generating a qrCode:
qrtools contains a class QR (can be viewed in the source code), for which we must initially create an object. The object takes the following arguments
data
pixel_size
level
margin_size
data_type
To create a QR code with default settings, we must simply specify the data while creating the object. Note that the data must be a unicode object if non-ASCII objects are going to be used.
# Python 2.x program to generate QR code from qrtools import QR # creates the QR object my_QR = QR(data = u"Example") # encodes to a QR code my_QR.encode() print my_QR.filename
print my_QR.filename
This file can now be moved to another folder as per our convenience# Python 2.x program to generate QR code from qrtools import QR import os my_QR = QR(data = u"Example") my_QR.encode() # command to move the QR code to the desktop os.system("sudo mv " + my_QR.filename + " ~/Desktop")
The pixel value of the QR code may also be changed by specifying the value during the creation of the QR object. The default size tends to be a little small for reading using scanners on smartphones, so a size of around 10 would be ideal for such purposes,
my_QR = QR(data = u"example", pixel_size = 10)</div>
Reading a QR code:
Scanning and reading a QR code is relatively simple. While creating the QR object, we must simply specify the path to the QR code as an argument. Suppose we are trying to decode the QR code created at the beginning of the article.
# Python 2.x program to Scan and Read a QR code from qrtools import QR my_QR = QR(filename = "home/user/Desktop/qr.png") # decodes the QR code and returns True if successful my_QR.decode() # prints the data print my_QR.data
Please write comments if you find anything incorrect, or you want to know more information.Please share if you like this post .Thank you

Comments
Post a Comment