首页 > 其他分享 >二维码,条形码——检测

二维码,条形码——检测

时间:2022-10-08 16:14:28浏览次数:37  
标签:条形码 img myData 检测 barcode cv2 二维码 pts 255

import cv2
import numpy
import pyzbar
from pyzbar.pyzbar import decode
#静态码识别
# path = 'aa.jpg '
# img = cv2.imread(path)
# # from PIL import Image
# # img = Image.open('aa.jpg')
# for barcode in decode(img):
# print(barcode.data) #码的内容 b:二进制
# print(barcode.rect) #码的位置
# print(barcode.type) #码的类型 QRCODE:二维码
# myData = barcode.data.decode('utf-8')
# print(myData)


#动态码识别
video = cv2.VideoCapture(0)

while True:
flag,img = video.read()
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
print(myData)
pts = numpy.array([barcode.polygon],numpy.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)

#动态对比
# with open() as f:
# mydatalist = f.read().splitlines()
# mydatalist = ['6931885788995','111111']
# print(mydatalist)
# video = cv2.VideoCapture(0)
# video.set(3,500)
# video.set(4,700)
# while True:
# flag,img = video.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 = numpy.array([barcode.polygon],numpy.int32)
# pts = pts.reshape((-1,1,2))
# cv2.polylines(img,[pts],True,(255,0,255),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)

标签:条形码,img,myData,检测,barcode,cv2,二维码,pts,255
From: https://www.cnblogs.com/lld76/p/15995199.html

相关文章