Python Scan qrcode realtime using camera

0 thích 0 không thích
1 lượt xem
đã hỏi 26 Tháng 5, 2021 trong Python bởi nguyenthao (9,000 điểm)
import cv2
import numpy as np
from pyzbar.pyzbar import Decoded, decode
cap = cv2.VideoCapture(0)
cap.set(3, 640)
cap.set(4, 480)
while True:
    success, img = cap.read()
    for barcode in decode(img):
        print(barcode.data)
        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,0), 2)
        
    cv2.imshow('Result', img)
    cv2.waitKey(1)

Looking for an answer?  Share this question:     

Xin vui lòng đăng nhập hoặc đăng ký để trả lời câu hỏi này.

...