【问题标题】:QR Code Detection from Pyzbar with Camera Image使用相机图像从 Pyzbar 检测二维码
【发布时间】:2018-04-28 20:49:33
【问题描述】:

我无法使用 Pyzbar 检测 QR 码。在完美条件下,我能够使用原始 png 图像检测 QR 码。但是,当我从相机进行视频捕获,然后将该帧保存为图像时,pyzbar 无法检测到 QR 码。

例如,这是可行的

[Decoded(data=b'GOAL', type='QRCODE', rect=Rect(left=16, top=16, width=168, height=168))]

但即使在我手动裁剪周围环境以仅显示二维码后,以下内容也没有。

[]

对于这两个图像,我都在使用

decode(image, scan_locations=True)

我想知道我需要做什么才能让 pyzbar 解码我的二维码图像?

【问题讨论】:

  • 尝试标准化,或者(可能更好)二值化图像以提高对比度。还有相当多的失真,您可能也需要考虑修复它。

标签: python opencv image-processing qr-code


【解决方案1】:

使用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)

打印输出显示解码类型为QRCODE,数据为GOAL

[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)])]

希望对您有所帮助。

【讨论】:

  • 你的变量mask是什么?
  • @cactuschibre thresholded
  • @Tinti 为了清晰起见,将阈值和倒置分成两行。谢谢。
【解决方案2】:

您面临的问题是由于您在处理之前翻转了图像

在使用 pyzbar 处理后翻转图像将使其对齐,就像你想要的那样

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-07
    • 2016-02-14
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多