【 实测可用 】python + CV2 视频识别 QR

需要:
电脑,摄像头,打印几个测试二维码
参考:
https://blog.csdn.net/kingroc/article/details/85265215
https://blog.csdn.net/kingroc/article/details/85265215
参考文章实现了本地图片识别,其实CV对摄像头也是按帧处理的,于是略修改实现摄像头前举着一张含有二维码的纸片,输出内容。
代码改的,有些乱,回头再优化

import cv2
import numpy as np

def display(im, bbox):
    n = len(bbox)
    for j in range(n):
        cv2.line(im, tuple(bbox[j][0]), tuple(bbox[(j + 1) % n][0]), (255, 0, 0), 3)

    # Display results
    cv2.imshow("Results", im)

# inputImage = cv2.imread("QR.jpg")
cap = cv2.VideoCapture(0)

qrDecoder = cv2.QRCodeDetector()

while(True):
    ret, inputImage = cap.read()
    # Detect and decode the qrcode
    data, bbox, rectifiedImage = qrDecoder.detectAndDecode(inputImage)
    if len(data) > 0:
        print("Decoded Data : {}".format(data))
        display(inputImage, bbox)
        rectifiedImage = np.uint8(rectifiedImage);
        cv2.imshow("Rectified QRCode", rectifiedImage);
    else:
        print("QR Code not detected")
        cv2.imshow("Results", inputImage)

cv2.waitKey(0)
cv2.destroyAllWindows()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值