Python-zxing decode returns empty data

2.5k views Asked by At

I've trying to decode qr or aztec code data by Python-zxing. Everytime I get empty data without any error in python Shell. What I do wrong?

import zxing
image = "aztec.png"

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

Output:

''
<zxing.BarCode instance at 0x0312A260>

Python ver. 2.7.11 (Windows)

P.S. When I run script from cmd I've message:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/zxing/client/j2se/CommandLineRunner

3

There are 3 answers

0
atgb On

Assuming the mvn installation of Zxing is correct,add the path of the Zxing folder while creating an instance of reader (in this case 'rd')

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

FYI: Am running it on Raspbian, not windows, but had the same error.

0
Khadeer Usman On
print(rs.raw)  # This returns the decoded text.

You can also use 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. 
0
ZF007 On

You forgot class inheritance. See below. Answer made compatible for python 3; but seriously... this is not the pep-way to do it. For long-term compatibility you should check by versioning and use an if-statement.

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)