Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the implementation code of scanning bar code and QR code in python

Shulou Source: shulou.com Published: 2022-06-03 07:41:46 09月24日 Update

Today, I will talk to you about the implementation code of scanning barcodes and QR codes in python. Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope you can gain something according to this article.

Simple explanation, code is too difficult to understand, make this record first and save it for future reading

Steps:

1, pip install pyzbar Install the module. Pyzbar module is Python an open source library for scanning and identifying QR code information.

2. Find two screenshots on the Internet.

3,

from pyzbar import pyzbarimport matplotlib.pyplot as pltimport cv2#bar code positioning and identification def decode(image,barcodes): #Cycle Monitoring Barcode for barcode in barcodes: #Extract barcode bounding box location #Draw the bounding box of the barcode in the figure (x,y,w,h)=barcode.rect#Get the x,y coordinates and width and height regions of this graph cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),5)#Frame it in blue, line thick 5 #Barcode data is byte object, so if you want to output on the image #Draw it, you need to replace it with a string first barcodeData=barcode.data.decode("utf-8")#Identify barcode data barcodeType=barcode.type#Type is also directly identified #Draw the barcode data and barcode type on the image text="{} ({})".format(barcodeData , barcodeType) cv2.putText(image,text,(x,y-10),cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,8,(255,0,0),2) # cv2.putText(image,text,(x,y-10) #Like terminal print barcode data and barcode type print("[INFO] Found {} barcode:{}".format(barcodeType,barcodeData)) plt.figure(figsize=(10,10)) plt.imshow(image) plt.show ()#1, Read barcode image image=cv2.imread ('tiaoxin.png ')bacodes=pyzbar.decode(image)#Find barcode in image and decode(image,bacodes)#Identify barcode #QR code image=cv2.imread ('erwei.png')bacodes=pyzbar.decode(image,bacodes) After reading the above content, do you have any further understanding of how to implement scanning barcode and QR code in python? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Tags: Bar bar code 2D QR code data code content type drawing picture module boundary location information area image coordinates character string byte Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Microsoft OPPO Reno MySQL