我在使用Pyzbar检测二维码时遇到问题。在完美的条件下,我能够使用原始的png图像来检测二维码。然而,当我从摄像头捕获视频,然后将该帧保存为图像时,pyzbar无法检测到二维码。
例如,这是可行的

[Decoded(data=b'GOAL', type='QRCODE', rect=Rect(left=16, top=16, width=168, height=168))]但是,即使在我手动裁剪了周围环境,只显示二维码之后,以下内容也没有显示出来。

[]对于这两个图像,我都使用
decode(image, scan_locations=True)我想知道我需要做什么才能让pyzbar解码我的二维码图像?
发布于 2018-05-26 04:25:47
使用OpenCV将图像阈值化为黑白,然后pyzbar能够解码二维码。
首先,使用下面的代码对图像进行阈值处理。
from pyzbar import pyzbar
import argparse
import numpy as np
import cv2
image =cv2.imread("QRCode.png")
# thresholds image to white in back then invert it to black in white
# try to just the BGR values of inRange to get the best result
mask = cv2.inRange(image,(0,0,0),(200,200,200))
thresholded = cv2.cvtColor(mask,cv2.COLOR_GRAY2BGR)
inverted = 255-thresholded # black-in-white以下是处理后的图像。

使用,
barcodes = pyzbar.decode(inverted)
print (barcodes)打印结果显示,解码后的数据类型为GOAL,解码类型为QRCODE。
[Decoded(data='GOAL', type='QRCODE', rect=Rect(left=5, top=13, width=228, height=212),
polygon=[Point(x=5, y=222), Point(x=233, y=225), Point(x=220, y=19), Point(x=13, y=13)])]希望这能有所帮助。
发布于 2019-09-10 05:45:08
您面临的问题是因为您在处理之前翻转了图像
使用pyzbar处理后翻转图像将使其按您所希望的方式对齐
https://stackoverflow.com/questions/50080949
复制相似问题