QR CODE GENERATOR AND DECODER
DESCRIPTION
The main concept of the article is to generate a QR code by taking the URL link as input and decoding the QR code to get the URL as output if we want to know the URL link.
Required libraries to execute the code and their installation code is:
PyQRCode library -> ("pip install PyQRCode")
PyPNG library -> ("pip install pypng")
OpenCV library -> (" pip install opencv-python")
PyQRCode library is used to generate the QR codes using python, PyPNG library is used for loading and saving PNG files, OpenCV library is a Realtime-Computer Vision library used to access the PNG file and decode it.
CODE
import pyqrcode
import png
from pyqrcode import QRCode
import cv2 as cv
s = "https://cppsecrets.com/"
url = pyqrcode.create(s)
url.svg("Profile.svg",scale = 8)
url.png('code.png', scale=6, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xcc])
im = cv.imread('code.png')
det = cv.QRCodeDetector()
retval, points, straight_qrcode = det.detectAndDecode(im)
print('URL Link is - ', retval)
EXPLANATION
After Importing the required libraries we use the functions to complete the task.
This function is used to create a QR code object by taking URL links as parameters.
url.svg("Profile.svg",scale = 8)
This function writes the QR code as an SVG (Scalable Vector Graphics) document.
url.png('code.png', scale=6, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xcc])
This function depends on the PyPNG library it is used to create a PNG file.
im = cv.imread('code.png')
This function is from OpenCV library it is used to access the PNG file.
det = cv.QRCodeDetector()
retval, points, straight_qrcode = det.detectAndDecode(im)
This function is used to Detect and Decode the PNG file and gives the result in a string, an array of vertices of the QR code quadrangle, an image containing rectified and binarized QR code.
OUTPUT
SVG FILE
PNG FILE
COMMAND PROMPT OUTPUT
Comments