Code Monkey home page Code Monkey logo

python-zxing's Introduction

python-zxing

PyPI Build Status License: LGPL v3

This is a wrapper for the ZXing barcode library. (It's a "slightly less quick-and-dirty" fork of oostendo/python-zxing.) It will allow you to read and decode barcode images from Python.

Dependencies and installation

Use the Python 3 version of pip (usually invoked via pip3) to install: pip3 install zxing

  • You'll neeed to have a recent java binary somewhere in your path. (Tested with OpenJDK.)
  • pip will automatically download the relevant JAR files for the Java ZXing libraries (currently v3.4.1)

Usage

The BarCodeReader class is used to decode images:

>>> import zxing
>>> reader = zxing.BarCodeReader()
>>> barcode = reader.decode("test/barcodes/QR_CODE-easy.png")
>>> print(barcode)
BarCode(raw='This should be QR_CODE', parsed='This should be QR_CODE', format='QR_CODE', type='TEXT', points=[(15.0, 87.0), (15.0, 15.0), (87.0, 15.0), (75.0, 75.0)])

The attributes of the decoded BarCode object are raw, parsed, format, type, and points. The list of formats which ZXing can decode is here.

The decode() method accepts an image path (or list of paths) and takes optional parameters try_harder (boolean), possible_formats (list of formats to consider), and pure_barcode (boolean). If no barcode is found, it returns None, and if it encounters any other recognizable error from the Java ZXing library, it raises BarCodeReaderException.

Command-line interface

The command-line interface can decode images into barcodes and output in either a human-readable or CSV format:

usage: zxing [-h] [-c] [--try-harder] image [image ...]

Human-readable:

$ zxing /tmp/barcode.png
/tmp/barcode.png
================
  Decoded TEXT barcode in QR_CODE format.
  Raw text:    'Testing 123'
  Parsed text: 'Testing 123'

CSV output (can be opened by LibreOffice or Excel):

$ zxing /tmp/barcode1.png /tmp/barcode2.png /tmp/barcode3.png
Filename,Format,Type,Raw,Parsed
/tmp/barcode1.png,CODE_128,TEXT,Testing 123,Testing 123
/tmp/barcode2.png,QR_CODE,URI,http://zxing.org,http://zxing.org
/tmp/barcode3.png,QR_CODE,TEXT,"This text, ""Has stuff in it!"" Wow⏎Yes it does!","This text, ""Has stuff in it!"" Wow⏎Yes it does!"

License

LGPLv3

python-zxing's People

Contributors

dlenski avatar oostendo avatar manouchehri avatar hjernefrys avatar ankita-kumari avatar graingert avatar vladvrabie avatar shatterhand19 avatar

Watchers

James Cloos avatar  avatar

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.