直接上代碼:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-609662.html
import cv2
from pyzbar.pyzbar import decode
cap = cv2.VideoCapture(0) # 打開(kāi)攝像頭
while True: # 循環(huán)讀取攝像頭幀
ret, frame = cap.read()
# 在循環(huán)中,將每一幀作為圖像輸入,使用pyzbar的decode()函數(shù)識(shí)別二維碼
barcodes = decode(frame)
# 繪制二維碼框和數(shù)據(jù)
for barcode in barcodes:
rect = barcode.rect
x, y, w, h = rect
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
data = barcode.data.decode("utf8")
cv2.putText(frame, data, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
print("Result:" + data)
# 顯示結(jié)果
cv2.imshow('Image', frame)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
簡(jiǎn)單使用的記錄文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-609662.html
到了這里,關(guān)于Python - Opencv + pyzbar實(shí)時(shí)攝像頭識(shí)別二維碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!