Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report