Active Hackathon

Guide to Generating & Testing QRcode Using OpenCV

Nowadays QR Code scanners have become popular because of their huge usage. QRcode stores some information in it. We can detect the QRcode from the image and we can decode the data in it. Mostly we can see QR codes are used by all e-payment apps and by their customers and every manufacturing product will have the product description in the form of a QRcode By just scanning the QRcode we will get info of that product. In this article, we will try to generate a QRcode and test a QRcode scanner with a few lines of code using the OpenCV modules pyzbar and qrcode.

Topics we cover in this article:-

  • QR Code Generation in Python
  • Introducing pyzbar module
  • How to Generate your own QR code
  • Scanning QR code using images

Hands-On Implementation

Now, we will implement our program on QR Code creation.


Sign up for your weekly dose of what's up in emerging technology.

 Importing required libraries

import cv2

import numpy as np

from google.colab.patches import cv2_imshow

Introducing pyzbar library

Pyzbar is an OpenCV module that is used to decode the QRcode and it is distributed under MIT license. Using this library it illustrates type: whether it is barcode or QRcode, data: the alphanumeric information is hidden in QRcode, and location: edges of the QRcode in the image.

Installing pyzbar library

pip install pyzbar

installing pyzbar

In the below code snippet we are installing the dependencies of the pyzbar library.

!apt install libzbar 

QR code in Python
installing lizar

Creating a QR code scanner

import qrcode

img = qrcode.make('')



image = cv2.imread("/content/qrcode_test.png")


QR code in Python
Generated QR code

Here we generated a QRcode code and I stored the Analytics India magazine link in this QRcode so that when scanning this QRcode the link appears.

Scanning QR code using images

image = cv2.imread("/content/download (13).jpg")

scan = pyzbar.decode(image)

for obj in scan:

    print("Type:", obj.type)

    print("Data:",, "\n")

Data =



QR code in Python
Scanning QR code

Here you can see we are getting the output type as QRcode and Data is the link we have given in the above snippet and we can try with any QRcode and it scans the information from the QRcode.


In this article, we demonstrated how to generate our own QRcode and how to scan QRcode and display information from it. Using OpenCV modules and a few lines of code in python we implemented the above code snippets. 

More Great AIM Stories

Prudhvi varma
AI enthusiast, Currently working with Analytics India Magazine. I have experience of working with Machine learning, Deep learning real-time problems, Neural networks, structuring and machine learning projects. I am a Computer Vision researcher and I am Interested in solving real-time computer vision problems.

Our Upcoming Events

Conference, Virtual
Genpact Analytics Career Day
3rd Sep

Conference, in-person (Bangalore)
Cypher 2022
21-23rd Sep

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan, 2023

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
21st Apr, 2023

Conference, in-person (Bangalore)
MachineCon 2023
23rd Jun, 2023

3 Ways to Join our Community

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Telegram Channel

Discover special offers, top stories, upcoming events, and more.

Subscribe to our newsletter

Get the latest updates from AIM

Council Post: How to Evolve with Changing Workforce

The demand for digital roles is growing rapidly, and scouting for talent is becoming more and more difficult. If organisations do not change their ways to adapt and alter their strategy, it could have a significant business impact.

All Tech Giants: On your Mark, Get Set – Slow!

In September 2021, the FTC published a report on M&As of five top companies in the US that have escaped the antitrust laws. These were Alphabet/Google, Amazon, Apple, Facebook, and Microsoft.

The Digital Transformation Journey of Vedanta

In the current digital ecosystem, the evolving technologies can be seen both as an opportunity to gain new insights as well as a disruption by others, says Vineet Jaiswal, chief digital and technology officer at Vedanta Resources Limited

BlenderBot — Public, Yet Not Too Public

As a footnote, Meta cites access will be granted to academic researchers and people affiliated to government organisations, civil society groups, academia and global industry research labs.