需要依赖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/{}".<