/README

http://github.com/oostendo/python-zxing · #! · 54 lines · 42 code · 12 blank · 0 comment · 0 complexity · 2c2d37908a452d4c94edb7c771b27fd9 MD5 · raw file

  1. python-zxing - a quick and dirty wrapper fo the [ZXing barcode library](http://code.google.com/p/zxing/)
  2. This is a hack subprocess control library that gives you a reasonable Python interface to the ZXing command line. ZXing will recognize and decode 1D and 2D
  3. barcodes in images, and return position information and decoded values. This
  4. will let you read barcodes from any images in Python.
  5. If you need to threshold or filter your image prior to sending to ZXing, I
  6. recommend using functions from [SimpleCV](http://sf.net/p/simplecv).
  7. Instructions for use
  8. wget http://zxing.googlecode.com/files/ZXing-1.6.zip
  9. cd zxing-1.6
  10. ant -f core/build.xml
  11. ant -f javase/build.xml
  12. git clone git://github.com/oostendo/python-zxing.git
  13. cd python-zxing
  14. nosetest tests.py
  15. The library consists of two classes, BarCodeReader and BarCode. BarCode parses
  16. the output from ZXing's CommandLineRunner into a BarCode object which includes:
  17. b = zxing.BarCode("""
  18. file:default.png (format: FAKE_DATA, type: TEXT):
  19. Raw result:
  20. foo-bar|the bar of foo
  21. Parsed result:
  22. foo-bar
  23. the bar of foo
  24. Also, there were 4 result points:
  25. Point 0: (24.0,18.0)
  26. Point 1: (21.0,196.0)
  27. Point 2: (201.0,198.0)
  28. Point 3: (205.23952,21.0)
  29. """)
  30. print b.format #FAKE_DATA
  31. print b.raw #foo-bar|the bar of foo
  32. print b.data #foo-bar\nthe bar of foo
  33. print b.points #[(24.0, 18.0) ... ]
  34. Initializing the barcode reader, you have to tell it where to find the ZXing
  35. core modules. It is the single parameter, which defaults to the parent
  36. directory.
  37. reader = zxing.BarCodeReader("/var/opt/zxing")
  38. barcode = reader.decode("/tmp/image.jpg")
  39. (barcode1, barcode2) = reader.decode(["/tmp/1.png", "/tmp/2.png"])
  40. code_list = reader.decode("/tmp/barcodes", True)
  41. decode() takes an image path, directory, or list of images and has an optional parameter to use the "try_harder" option. If no barcode is found, it returns None objects.
  42. Installation is manual.