QR Code & Bar Code Detection Using Open CV Python With Source Code

Introduction :
Today We Make a QR Code & Bar Code Detector Using Open CV Python , A Versatile Programming Language . To Make the Detector , We need some modules or Packages from Python Library Like numpy , cv2 , qrcode . Open CV is a Powerfull Computer Vision Library . QR Code & Bar Code Detection is a very essential feature in modern Application . Eg :- In Phonpe app , we can Pay Money by scannig Qr Code . QR Code , which store data in two dimensional matrix . Barcode , which store informations in linear patterns . Open CV Is used to Detecting & Decoding these types of codes and extract their information stored in These Codes .
Language And Interface :-
QR Code & Bar Code Detection Using Python , A Versatile Programming Language With
Source Code .
Required Modules Or Packages:-
You Need The Packages List Given Below :-
1. Numpy :- It is a core library for numerical computation in python and it can handle large arrays of numbers.
2. cv2 :- It is a library to use in Computer Vision task. You will get basic image processing tools while using cv2 for example, Image Reading and Writing .
3. pyzbar.pyzbar :- It is used to Decode the Bar code .
4. qrcode :- It is used to detecting and generating the qr codes .
How To Run The Code :-
Step 1 . First , You Download and Install Visual Studio Code or VS Code In your PC or Laptop by VS Code Official Website .
Step 2 . Now Open CMD As Administrator and install the above packages using pip .
Step 3 . Now Open Visual Studio Code .
Step 4. Now Make The files named as qrbartest.py, qrcodeproject.py .
Step 5 . Now Copy And Paste The Code from the Link Given Below
Step 6 . After pasting The code , Save This & Click On Run Button .
Step 7 . Now You will See The Output .
Code Explanation :-
This Python code is used to Detect the QR Codes and Bar Codes and extract the informations stored in it from Any Image Files format .
Step-by-Step Guide Given Below:-
Imports:
• Numpy :- It is a core library for numerical computation in python and it can handle large arrays of numbers.
• cv2 :- It is a library to use in Computer Vision task. You will get basic image processing tools while using cv2 for example, Image Reading and Writing .
• pyzbar.pyzbar :- It is used to Decode the Bar code .
• qrcode :- It is used to detecting and generating the qr codes .
cv2.VideoCapture(0) : It is used to capture the video , where (0) selects the default webcam . decode from pyzbar : It is used to Detect the QR Codes and Bar Codes .
cv2.polylines : It is used to extract the coordinates of barcode’s corner and convert into
a polygon .
cv2.putText : It is used to overlaiding the decoded data from QR Code on the video frame at
the position of the detected code .
cv2.waitkey(1) : It is Used to smooth Video Playback and updating every mili seconds .
Overall :
This code create a Simple and effective QR Code & Bar code detector . It Displays the
scanned code and decoded code .
Get Discount on Top Educational Courses
Source Code :-
Here Is Your Code Link From Where You Can Access or Copy The Code :-
QrBarTest.py
import cv2
import numpy as np
from pyzbar.pyzbar import decode
#img = cv2.imread('1.png')
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
while True:
success, img = cap.read()
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
print(myData)
pts = np.array([barcode.polygon],np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,(255,0,255),5)
pts2 = barcode.rect
cv2.putText(img,myData,(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SIMPLEX,
0.9,(255,0,255),2)
cv2.imshow('Result',img)
cv2.waitKey(1)
QrCodeProject.py
import cv2
import numpy as np
from pyzbar.pyzbar import decode
#img = cv2.imread('1.png')
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
with open('myDataFile.text') as f:
myDataList = f.read().splitlines()
while True:
success, img = cap.read()
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
print(myData)
if myData in myDataList:
myOutput = 'Authorized'
myColor = (0,255,0)
else:
myOutput = 'Un-Authorized'
myColor = (0, 0, 255)
pts = np.array([barcode.polygon],np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,myColor,5)
pts2 = barcode.rect
cv2.putText(img,myOutput,(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SIMPLEX,
0.9,myColor,2)
cv2.imshow('Result',img)
cv2.waitKey(1)
Output :-

Find More Projects
Whack a Mole Game with HTML CSS And JavaScript Introduction Hello friends, you all are welcome to today’s beautiful and unique project. Today …
3D Car Driving Game Using Html CSS And JavaScript Introduction Hello friends, welcome to today’s new blog post. Today we have created …
Dice Rolling Game Using HTML CSS And JavaScript Introduction Hey coders, welcome to another new blog. In this article we’ll build a …
Crossey Road Game Clone Using HTML CSS And JavaScript Introduction This is our HTML code which sets up the basic structure of …
Memory Card Game Using HTML CSS And JavaScript Introduction Hello coders, welcome to another new blog. Today in this article we’ll learn …
sudoku game using html CSS and JavaScript Introduction Hello friends, you all are welcome to today’s beautiful project. Today we have made …