无法使用带有 python3 的 pyzbar 解码二维码
Can not decode QR code using pyzbar with python3
我需要使用 python3、opencv 和 pyzbar 解码 this QR Code,但我无法获得任何好的结果:脚本无法 detect/decode QR代码.
这是我用过的代码。有什么好的方法可以提高识别度吗?
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)
在应用 QR 解码器之前,我还尝试了:
更改brightness/contrast:
# Change brightness/contrast
image = cv2.convertScaleAbs(image, alpha=6, beta=0)
制作二值图像:
# Make binary image
image[image > 19] = 255
image[image <= 19] = 0
旋转图像(using this function):
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)
好的,我发现我要解码的图像不是二维码,而是数据矩阵条码。现在使用 pylibdmtx 我可以解码它。
我需要使用 python3、opencv 和 pyzbar 解码 this QR Code,但我无法获得任何好的结果:脚本无法 detect/decode QR代码.
这是我用过的代码。有什么好的方法可以提高识别度吗?
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)
在应用 QR 解码器之前,我还尝试了:
更改brightness/contrast:
# Change brightness/contrast
image = cv2.convertScaleAbs(image, alpha=6, beta=0)
制作二值图像:
# Make binary image
image[image > 19] = 255
image[image <= 19] = 0
旋转图像(using this function):
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)
好的,我发现我要解码的图像不是二维码,而是数据矩阵条码。现在使用 pylibdmtx 我可以解码它。