Barcode and QR Code Reader or Scanner with OpenCV in Python

Barcode and QR Code Reader using OpenCV in Python With Source Code

The Barcode and QR Code Reader OpenCV Python was developed using Python OpenCV. In this post, I will show you how to build a Barcode and QR Code reader using Python.

This is a great machine learning project to get started with computer vision.

A Barcode Reader OpenCV Python is very cool and interesting because they store information in a different format. The fun part about them is we can’t really tell what they are storing until we scan them.

It’s like playing a puzzle game. One more thing that I like about them is they can be part of the physical world and still connect us to the internet world.

This Python OpenCV Project also includes a downloadable Python Project With Source Code for free, just find the downloadable source code below and click to start downloading.

What is OpenCV?

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library.

OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products.

By the way, if you are new to Python programming and don’t know what Python IDE is, I have here a list of the Best Python IDEs for Windows, Linux, and Mac OS that will suit you.

I also have here How to Download and Install the Latest Version of Python on Windows.

To start executing Barcode and QR Code Reader OpenCV Python With Source Code, make sure that you have installed Python 3.9 and PyCharm on your computer.

How to run the Barcode and QR Code Reader or Scanner using OpenCV in Python: Step-by-Step Guide with source code

Time needed: 5 minutes

These are the steps on how to run Barcode and QR Code Reader OpenCV Python With Source Code

  • Step 1: Download the given source code below.

    First, download the given source code below and unzip the source code.
    barcode and qr code reader download source code

  • Step 2: Import the project to your PyCharm IDE.

    Next, import the source code you’ve downloaded to your PyCharm IDE.
    barcode and qr code reader open project

  • Step 3: Run the project.

    Lastly, run the project with the command “py main.py”
    barcode and qr code reader run project

Installed Libraries

from pyzbar import pyzbar
import cv2

Complete Source Code

from pyzbar import pyzbar
import cv2

image = cv2.imread('Qr.png')
barcodes = pyzbar.decode(image)
for barcode in barcodes:
    (x, y, w, h) = barcode.rect
    cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)

    barcodeData = barcode.data.decode('utf-8')
    barcodeType = barcode.type
    text = "{} ( {} )".format(barcodeData, barcodeType)
    cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_COMPLEX, 0.5, (255, 0, 0), 2)

    print("Information : \n Found Type : {} Barcode : {}".format(barcodeType, barcodeData))

cv2.imshow("Image", image)
cv2.waitKey(0)

Download the Source Code below

Summary

I think Barcodes/QR codes are very cool and interesting because they store information in a different format.

The fun part about them is we can’t really tell what they are storing until we scan them.

It’s like playing a puzzle game. One more thing that I like about them is they can be part of the physical world and still connect us to the internet world.

Related Articles

Inquiries

If you have any questions or suggestions about Barcode and QR Code Reader OpenCV Python With Source Code, please feel free to leave a comment below.

Leave a Comment