0

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

ssnake
  • 365
  • 2
  • 14

3 Answers3

0

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.

atgb
  • 3
  • 4
0

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)
ZF007
  • 3,708
  • 8
  • 29
  • 48
-1
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. 
ToughMind
  • 987
  • 1
  • 10
  • 28