Code Monkey home page Code Monkey logo

python-zxing's Introduction

python-zxing

A quick and dirty wrapper for the ZXing barcode library.

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 barcodes in images, and return position information and decoded values. This will let you read barcodes from any images in Python.

If you need to threshold or filter your image prior to sending to ZXing, I recommend using functions from SimpleCV.

Usage

git clone https://github.com/zxing/zxing.git
cd zxing-master
mvn install
cd core
wget http://central.maven.org/maven2/com/google/zxing/core/2.2/core-2.2.jar
mv core-2.2.jar core.jar # Rename
mvn install
cd zxing-master/javase
wget http://central.maven.org/maven2/com/google/zxing/javase/2.2/javase-2.2.jar 
mv javase-2.2.jar javase.jar # Rename
mvn install
git clone git://github.com/oostendo/python-zxing.git

The library consists of two classes, BarCodeReader and BarCode. BarCode parses the output from ZXing's CommandLineRunner into a BarCode object which includes:

b = zxing.BarCode("""
file:default.png (format: FAKE_DATA, type: TEXT):
Raw result:
foo-bar|the bar of foo
Parsed result:
foo-bar 
the bar of foo
Also, there were 4 result points:
  Point 0: (24.0,18.0)
  Point 1: (21.0,196.0)
  Point 2: (201.0,198.0)
  Point 3: (205.23952,21.0)
""")

print b.format #FAKE_DATA
print b.raw #foo-bar|the bar of foo
print b.data #foo-bar\nthe bar of foo
print b.points #[(24.0, 18.0) ... ]

Initializing the barcode reader, you have to tell it where to find the ZXing core modules. It is the single parameter, which defaults to the parent directory.

reader = zxing.BarCodeReader("/var/opt/zxing")

barcode = reader.decode("/tmp/image.jpg")
(barcode1, barcode2) = reader.decode(["/tmp/1.png", "/tmp/2.png"])
code_list = reader.decode("/tmp/barcodes", True)

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.

Installation is manual.

python-zxing's People

Contributors

ankita-kumari avatar graingert avatar hjernefrys avatar manouchehri avatar oostendo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-zxing's Issues

Unnecessary to perform 'mvn install' more than once

You only need to run mvn install once from the zxing directory, and considering that working zxing-X.jar files already exist in the core/target/ and javase/target/ directories, I'm not sure the wget ... lines are necessary either.

Pass image instead of image path

Hello,

I want to pass the image directly instead of the image path.

img=cv2.imread('IMG_1736.JPG')

barcode_reader(str(img)

How can I do that

no main manifest attribute in javase/javase.jar

I know nothing about java, and I merely follow the readme instructions to install zxing and the wrapper.
When I try a simple call to the decoder, this problem pops up:

no main manifest attribute in home/zxing/javase/javase.jar

Can anyone tell me how to solve this problem?

The simple code snippet:

from zxing import *
img = 'sample.png'

zx = BarCodeReader('/home/zxing')
barcode = zx.decode(img)

The readme is unclear for non Java experts

I have close to no knowledge about java and could not have python-zxing working.

The README.md file states Initializing the barcode reader, you have to tell it where to find the ZXing core modules. It suggests /var/opt/zxing. However, there is no zxing directory in /var/opt after having followed the steps in Section "Usage".

After a few trials and error, I managed to run it by using the maven build directory:

zxing_scanner = zxing.BarCodeReader('/home/gael/04-build/zxing/zxing')
barcode = reader.decode('/tmp/image.jpg')

I wanted to install zxing globaly or as user but don't know how to do it. I noticed though that there is something related to zxing in ~/.m2/repository/com/google/zxing (there is ~/.m2/repository/com/google/zxing/core/3.2.1/core-3.2.1.jar but no core.jar) and wanted to use it. What I tried (I tried all commented lines with the same results):

# reader = zxing.BarCodeReader('/home/gael/.m2/repository/com/google/zxing/core/')
# reader = zxing.BarCodeReader('/home/gael/.m2/repository/com/google/zxing/core/3.2.1')
reader = zxing.BarCodeReader('/home/gael/.m2/repository')
barcode = reader.decode('/tmp/image.jpg')

I got:

Error: Could not find or load main class com.google.zxing.client.j2se.CommandLineRunner

I think it would be appropriate to give more details in the README.md file.

Could not find or load main class com.google.zxing.client.j2se.CommandLineRunner

I am getting this error when trying to run this code - it appears zxing is installed:

computer$ java -cp javase/javase.jar:core/core.jar com.google.zxing.client.j2se.CommandLineRunner
Decode barcode images using the ZXing library

usage: CommandLineRunner { file | dir | url } [ options ]
--try_harder: Use the TRY_HARDER hint, default is normal (mobile) mode
--pure_barcode: Input image is a pure monochrome barcode image, not a photo
--products_only: Only decode the UPC and EAN families of barcodes
--dump_results: Write the decoded contents to input.txt
--dump_black_point: Compare black point algorithms as input.mono.png
--crop=left,top,width,height: Only examine cropped region of input image(s)

`mvn install ` fails because of unapproved licenses

mvn install reports the following:

4 Unknown Licenses

*******************************

Unapproved licenses:

  python-zxing/setup.py
  python-zxing/zxing/tests.py
  python-zxing/zxing/__init__.py
  python-zxing/MANIFEST

Non-mvn instructions

The readme gives usage instructions that need maven. As I'm making a python application, it wouldn't be appropriate for me to ask my users to install maven and build maven packages.
Isn't there a standalone jar file or so that they can simply download and use ?

pip install - Throw errors if dependencies not found

pip install works even if some of the main dependencies like java are not found.

Currently the package asks for the zxing java library's path. Which isn't very helpful for people who wish to make packages out of this. (We can't as the user to tell us the xzing path, because they won't know !)

It would be better is the setup.py downloads the appropriate files itself and uses these downloaded files when it needs them. Otherwise, the installation of this package and it's dependencies is too be complicated to be used in python projects.

how to take bytes as input instead of image path?

As described in the README, reader.decode() takes image path as parameter:
reader = zxing.BarCodeReader("/var/opt/zxing")
barcode = reader.decode("/tmp/image.jpg")

How to take bytes instead of image path? For example:
with open('/tmp/image.jpg','rb') as img_file:
img_bytes = img_file.read()
barcode = reader.decode(img_bytes)

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.