Creating a QR Code Generator and Reader



Creating a QR Code Generator and Reader


Welcome back to another tutorial on Python.

Today we will be creating a QR Code generator and also read it with Python.

So, for creating a QR Code, you need a package named qrcode .
We can install it using the command line.

pip install qrcode

After installing this package go to your favourite editor and create a file.

Now, just import the package

import qrcode

Now we just need to take the input for which we would be making a link. It can be a number, text, link or anything and convert it to the QR Code.

path = input("Enter link to create QR Code : ")
img = qrcode.make(path)
imgName = input("Enter save file name : ")
img.save(imgName+'.jpg')

Now, we are set to create our QR Code.
You just try and tell in the comments if there is an error in the code.

Now we will just read our QR Code and tell what it contains.
For this we will need another package named cv2 .
Just head over to the command line and type the following command -


pip install opencv-python

Now in the file created just import this package.

import opencv-python

Now, we will setup our QR Code Detector and give the path to the QR Code.
The module will decode it for us.

d = cv2.QRCodeDetector()
path = input("Enter path to QR Code: ")
val, _, _ = d.detectAndDecode(cv2.imread(path))
print(val)

For the full code, 

Now we are just good to go.
We have successfully created a program to read and create a QR Code.
We will be back soon with an another amazing tutorial.

0 Comments

Newest