视频扫描二维码

视频扫描二维码

coding:utf8

import cv2
import pyzbar.pyzbar as pyzbar

def decodeDisplay(image):

barcodes = pyzbar.decode(image)
for barcode in barcodes:
    # 提取条形码的边界框的位置
    # 画出图像中条形码的边界框
    (x, y, w, h) = barcode.rect
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)

    # 条形码数据为字节对象,所以如果我们想在输出图像上
    # 画出来,就需要先将它转换成字符串
    barcodeData = barcode.data.decode("utf-8")
    barcodeType = barcode.type

    # 绘出图像上条形码的数据和条形码类型
    text = "{} ({})".format(barcodeData, barcodeType)
    cv2.putText(image, text, (x, y - 10), 
    cv2.FONT_HERSHEY_SIMPLEX,0.5, (0, 0, 125), 2)

    # 向终端打印条形码数据和条形码类型
    print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
return image

def detect():
camera = cv2.VideoCapture(0)
while True:
# 读取当前帧
ret, frame = camera.read()
# 转为灰度图像
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
im=decodeDisplay(gray)

    cv2.waitKey(5)
    cv2.imshow("camera", im)

camera.release()
cv2.destroyAllWindows()

if name == ‘main’:
detect()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值