【发布时间】:2020-09-06 17:53:12
【问题描述】:
我需要使用 python3、opencv 和 pyzbar 解码 this QR Code,但我无法获得任何好的结果:脚本无法检测/解码 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 解码器之前,我还尝试过:
改变亮度/对比度:
# 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)
【问题讨论】: