Barcode and QR Code Reader OpenCV Python With Source Code

Barcode and QR Code Reader OpenCV 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 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. And one more thing that I like about them is they can be part of the physical world and still connects us to the internet world.

In 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 you don’t know what would be the the Python IDE to use, I have here a list of Best Python IDE for Windows, Linux, Mac OS that will suit for you. I also have here How to Download and Install 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 in your computer.

Barcode and QR Code Reader OpenCV Python With Source Code : Steps on how to run the project

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 download to your PyCharm IDE.
    barcode and qr code reader open project

  • Step 3: Run the project.

    last, 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 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. And one more thing that I like about them is they can be part of the physical world and still connects 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