0

我试图通过 Python-zxing 解码 qr 或 aztec 代码数据。每次我在 python Shell 中得到空数据而没有任何错误。我做错了什么?

import zxing
image = "aztec.png"

rd = zxing.BarCodeReader()
rs = rd.decode(image)
print rs.data
print rs

输出:

''
<zxing.BarCode instance at 0x0312A260>

蟒蛇版。2.7.11 (Windows)

PS 当我从 cmd 运行脚本时,我有消息:

线程“主”java.lang.NoClassDefFoundError 中的异常:com/google/zxing/client/j2se/CommandLineRunner

4

3 回答 3

0

假设 Zxing 的 mvn 安装是正确的,在创建 reader 实例时添加 Zxing 文件夹的路径(在本例中为 'rd')

rd = zxing.BarCodeReader("/path/to/zxing")

仅供参考:我在 Raspbian 上运行它,而不是 Windows,但有同样的错误。

于 2016-07-20T08:02:01.673 回答
0

你忘记了类继承。见下文。答案与 python 3 兼容;但说真的......这不是做这件事的鼓舞人心的方式。为了长期兼容性,您应该通过版本控制进行检查并使用 if 语句。

image = "aztec.png"

zxing = zxing() # notice zxhing()

rd = zxing.BarCodeReader()   
rs = rd.decode(image)
try:
    print (rs.data)
    print (rs)
except:
    print (rs.data)
    print (rs)
于 2019-12-30T09:21:50.907 回答
-1
print(rs.raw)  # This returns the decoded text.

您也可以使用 rs.parsed。

print(rs.format)  # This returns the Format like the detected one is DataMatrix. QR Code etc.

print(rs.points)  # This returns the boundary of points where its detected. 
于 2019-12-30T07:26:03.967 回答