使用pyzbar解析二维码图片

本文介绍如何使用Pyzbar库解析二维码图片。该库依赖于zbar,确保正确安装后,可以方便地处理二维码读取任务。
摘要由CSDN通过智能技术生成

需要依赖pyzbar库,依赖zbar库,可搜索安装。

from pyzbar.pyzbar import decode
from PIL import Image
import os
import cv2
import numpy as np


def test_image_dir():
    for one in os.listdir("./images"):
        # image=cv2.imread(filepath)
        image = Image.open("./images/" + one)
        results = decode(image)

        info = "{}\t size: {} ".format(one, len(results))
        for res in results:
            info += "{}({}), {}\t".format(res.data, res.type, res.rect)
        # print("size: {}".format(len(a)))
        # print(a[0].type, a[0].data, a[0].rect)
        print(info)


"""
[
    Decoded(
        data=b'Foramenifera', type='CODE128',
        rect=Rect(left=37, top=550, width=324, height=76),
        polygon=[
            Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
            Point(x=361, y=550)
        ]
    )
    Decoded(
        data=b'Rana temporaria', type='CODE128',
        rect=Rect(left=4, top=0, width=390, height=76),
        polygon=[
            Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
            Point(x=394, y=0)
        ]
    )
]
"""

import requests as req
from io import BytesIO
import base64


def test_image_url():
    all_no = 0
    right_no = 0

    # 329/393   0.83715
    qr_file = "image_urls.txt"

    # 150 0标签, 其他所有数据
    no_qr_file = "not_qr_image_urls.txt"

    with open(no_qr_file) as f:
        for line in f:
            key = line.strip()

            url = "https://si.geilicdn.com/{}".<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值