使用pyzbar与python3无法解码二维码。

问题描述 投票:0回答:1

我需要解码 此二维码 使用python3,opencv和pyzbar,但我无法得到任何好的结果:脚本无法检测到二维码的解码。

这是我使用的代码。有什么好的方法可以提高识别度吗?

import cv2
from pyzbar import pyzbar

# Image load
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
args = vars(ap.parse_args())
image = cv2.imread(args["image"])

# Read QR
qr_code = pyzbar.decode(image)
print(qr_code)

在应用二维码解码器之前,我还试过。

改变亮度和对比度

# Change brightness/contrast
image = cv2.convertScaleAbs(image, alpha=6, beta=0)

做一个二进制图像

# Make binary image
image[image > 19] = 255
image[image <= 19] = 0

旋转图像 (使用该函数):

def rotate_image(image, angle):
    image_center = tuple(np.array(image.shape[1::-1]) / 2)
    rot_mat = cv2.getRotationMatrix2D(image_center, angle, 1.0)
    result = cv2.warpAffine(image, rot_mat, image.shape[1::-1], flags=cv2.INTER_LINEAR)
    return result

image = rotate_image(image, 7)
python qr-code
1个回答
0
投票

好吧,我发现我试图解码的图像不是一个QR码,而是一个数据矩阵条码。现在使用 pylibdmtx 我可以破解它。

© www.soinside.com 2019 - 2024. All rights reserved.