Reading and Generating QR codes using QRtools:

In the following discussion, we will discuss a Python library qrtools for Data Science. The library can be there for both reading QR codes and for generating them too.

QR codes:

QR code or in other words quick response code, is a trademark for a two dimensional barcode. The 2-dimensional barcodes are similar to one-dimensional ones, but they can store much more information per unit area.

Installation and Dependencies:
  1. Debian Linux: The qrtools will be installed on debian based Linux systems by using the below commands.

We should install the following dependencies :

Reading or Generating QR code using QRtools in Python for Data Science

  1. Windows: The qrtools can be installed on Windows by downloading file from here. On downloading and extracting, we should run the below command from inside the folder.

Generating a QR code:

The qrtools consists of a class QR. An object should be created initially for this. The following arguments are taken by the object.

  • Data
  • Pixel_size
  • Level
  • Margin_size
  • Data_type

For the creation of QR code with default settings, we must specify the data while creation of the object. The data must be a Unicode object in case non-ASCII objects are there.

In case the program has a successful run, it will return a value of 0 and the QR code generated is stored in the tmp file. In order to find the exact location of the code, we use the following command

OUTPUT:

Reading or Generating QR code using QRtools in Python for Data Science

We can move the file to another folder as we wish.

Reading or Generating QR code using QRtools in Python for Data Science

We can also change the pixel value of QR code by specifying the value while creation of QR object. The QR code generated in the above example is small and is not readable properly, so a QR code of size 10 would be ideal.

Reading or Generating QR code using QRtools in Python for Data Science

In the code above, it can be seen that various data types can be assigned and can use while creation of QR codes. For example, in order to use a bookmark as data we must use data as list, which consists of a title and url. To accomplish this thing, we must do the following.

Reading a QR code:

It is simple to scan and read a QR code. While creation of QR object, we must specify the path to QR code as argument. Imagine we are trying to decode QR code created at the beginning of our discussion.

OUTPUT:

We can print the values of other parameters passed while creation of the QR object in order to generate the QR code, example using same QR code generated at the beginning of the article. If we add these print statements we will get the following additional output:

Reading or Generating QR code using QRtools in Python for Data Science

Reading or Generating QR code using QRtools in Python for Data Science

To learn more bout QRs in python for Data Science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.