Python program to generate QR Code

 

Python program to generate QR Code to encode Secrete Data

Write a python program to generate a QR Code to store secrete data (information) and decode the QR Code to get (retrieve) secrete data (information).

Video Tutorial

Installing Necessary Libraries to generate a QR Code

Following libraries are required to generate a QR code to store data and retrieve data from QRcode.

  1. qrcode
  2. qrcode[pil]
  3. opencv-python

Use the following commands to install the above libraries:

pip install qrcode

pip install qrcode[pil]

pip install opencv-python

Source Code to QR Code to store secrete data in python

import qrcode

# Create The variable to store the information
data = "Welcome to Mahesh Huddar YouTube Channel"

# Encode The Data
img = qrcode.make(data)

# Save the QR Code
img.save("QRCode.jpg")

Here first we, import qrcode library. Then data variable is created to store the information to be encoded. Then make() the function of qrcode is used to generate the QR code. Finally, the QR code is stored in the machine using the save() function.

Output

Python program to generate QR Code

Source Code to QR Code to retrieve secrete data in python

import cv2

# Create The Decoder
decoder = cv2.QRCodeDetector()

# Load Your Data
image = cv2.imread("QRCode.jpg")

# Decode and Print the required information
data, data_points, straight_qrcode = decoder.detectAndDecode(image)
print(data)

Here first, we import the cv2 library. The decoder object of QRCodeDetector is created. Then the QRcode image is read using imread() function of opencv (cv2). Finally, the detectAndDecode() function is used to decode the secreted information from the QR code. The result is printed using the print statement.

Output:

Welcome to Mahesh Huddar YouTube Channel

Summary:

This tutorial discusses how to write Python to generate a QR Code to store secrete data (information) and decode the QR Code to get (retrieve) secrete data (information). If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

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