pyzbar


Namepyzbar JSON
Version 0.1.9 PyPI version JSON
download
home_pagehttps://github.com/NaturalHistoryMuseum/pyzbar/
SummaryRead one-dimensional barcodes and QR codes from Python 2 and 3.
upload_time2022-03-15 14:53:40
maintainer
docs_urlNone
authorLawrence Hudson
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            pyzbar
======

.. image:: https://img.shields.io/badge/python-2.7%2C%203.5%2C%203.6%2C%203.7%2C%203.8%2C%203.9%2C%203.10-blue.svg
    :target: https://github.com/NaturalHistoryMuseum/pyzbar

.. image:: https://badge.fury.io/py/pyzbar.svg
    :target: https://pypi.python.org/pypi/pyzbar

.. image:: https://img.shields.io/github/workflow/status/NaturalHistoryMuseum/pyzbar/Tests/master?label=tests
    :target: https://github.com/NaturalHistoryMuseum/pyzbar/actions?query=workflow%3A%22Tests%22

.. image:: https://coveralls.io/repos/github/NaturalHistoryMuseum/pyzbar/badge.svg?branch=master
    :target: https://coveralls.io/github/NaturalHistoryMuseum/pyzbar?branch=master

Read one-dimensional barcodes and QR codes from Python 2 and 3 using the
`zbar <http://zbar.sourceforge.net/>`__ library.

-  Pure python
-  Works with PIL / Pillow images, OpenCV / imageio / numpy ``ndarray``\ s, and raw bytes
-  Decodes locations of barcodes
-  No dependencies, other than the zbar library itself
-  Tested on Python 2.7, and Python 3.5 to 3.10

The older `zbar <https://sourceforge.net/p/zbar/code/ci/default/tree/python/>`__
package is stuck in Python 2.x-land.
The `zbarlight <https://github.com/Polyconseil/zbarlight/>`__ package does not
provide support for Windows and depends upon Pillow.

Installation
------------

The ``zbar`` DLLs are included with the Windows Python wheels.
On other operating systems, you will need to install the ``zbar`` shared
library.

Mac OS X:

::

   brew install zbar

Linux:

::

   sudo apt-get install libzbar0

Install this Python wrapper; use the second form to install dependencies of the
command-line scripts:

::

   pip install pyzbar
   pip install pyzbar[scripts]

Example usage
-------------

The ``decode`` function accepts instances of ``PIL.Image``.

::

   >>> from pyzbar.pyzbar import decode
   >>> from PIL import Image
   >>> decode(Image.open('pyzbar/tests/code128.png'))
   [
       Decoded(
           data=b'Foramenifera', type='CODE128',
           rect=Rect(left=37, top=550, width=324, height=76),
           polygon=[
               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
               Point(x=361, y=550)
           ],
           orientation="UP",
           quality=77
       )
       Decoded(
           data=b'Rana temporaria', type='CODE128',
           rect=Rect(left=4, top=0, width=390, height=76),
           polygon=[
               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
               Point(x=394, y=0)
           ],
           orientation="UP",
           quality=77
       )
   ]

It also accepts instances of ``numpy.ndarray``, which might come from loading
images using `OpenCV <http://opencv.org/>`__.

::

   >>> import cv2
   >>> decode(cv2.imread('pyzbar/tests/code128.png'))
   [
       Decoded(
           data=b'Foramenifera', type='CODE128',
           rect=Rect(left=37, top=550, width=324, height=76),
           polygon=[
               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
               Point(x=361, y=550)
           ],
           orientation="UP",
           quality=77
       )
       Decoded(
           data=b'Rana temporaria', type='CODE128',
           rect=Rect(left=4, top=0, width=390, height=76),
           polygon=[
               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
               Point(x=394, y=0)
           ],
           orientation="UP",
           quality=77
       )
   ]

You can also provide a tuple ``(pixels, width, height)``, where the image data
is eight bits-per-pixel.

::

   >>> image = cv2.imread('pyzbar/tests/code128.png')
   >>> height, width = image.shape[:2]

   >>> # 8 bpp by considering just the blue channel
   >>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height))
   [
       Decoded(
           data=b'Foramenifera', type='CODE128',
           rect=Rect(left=37, top=550, width=324, height=76),
           polygon=[
               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
               Point(x=361, y=550)
           ],
           orientation="UP",
           quality=77
       )
       Decoded(
           data=b'Rana temporaria', type='CODE128',
           rect=Rect(left=4, top=0, width=390, height=76),
           polygon=[
               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
               Point(x=394, y=0)
           ],
           orientation="UP",
           quality=77
       )
   ]

   >>> # 8 bpp by converting image to greyscale
   >>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
   >>> decode((grey.tobytes(), width, height))
   [
       Decoded(
           data=b'Foramenifera', type='CODE128',
           rect=Rect(left=37, top=550, width=324, height=76),
           polygon=[
               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
               Point(x=361, y=550)
           ],
           orientation="UP",
           quality=77
       )
       Decoded(
           data=b'Rana temporaria', type='CODE128',
           rect=Rect(left=4, top=0, width=390, height=76),
           polygon=[
               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
               Point(x=394, y=0)
           ],
           orientation="UP",
           quality=77
       )
   ]

   >>> # If you don't provide 8 bpp
   >>> decode((image.tobytes(), width, height))
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/Users/lawh/projects/pyzbar/pyzbar/pyzbar.py", line 102, in decode
       raise PyZbarError('Unsupported bits-per-pixel [{0}]'.format(bpp))
   pyzbar.pyzbar_error.PyZbarError: Unsupported bits-per-pixel [24]

The default behaviour is to decode all symbol types. You can look for just your
symbol types

::

   >>> from pyzbar.pyzbar import ZBarSymbol
   >>> # Look for just qrcode
   >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.QRCODE])
   [
       Decoded(
           data=b'Thalassiodracon', type='QRCODE',
           rect=Rect(left=27, top=27, width=145, height=145),
           polygon=[
               Point(x=27, y=27), Point(x=27, y=172), Point(x=172, y=172),
               Point(x=172, y=27)
           ],
           orientation="UP",
           quality=1
       )
   ]


   >>> # If we look for just code128, the qrcodes in the image will not be detected
   >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128])
   []

ZBar versions
-------------

Development of the `original zbar <http://zbar.sourceforge.net/>`__ stopped in 2012.
Development was started again in 2019 under a `new project <https://github.com/mchehab/zbar/>`__
that has added some new features, including support for decoding
barcode orientation. At the time of writing this new project does not produce Windows DLLs.
The ``zbar`` DLLs that are included with the Windows Python wheels are built from the original
project and so do not include support for decoding barcode orientation.
If you see ``orientation=None`` then your system has an older release of zbar that does
not support orientation.

Quality field
-------------
From
`zbar.h <https://sourceforge.net/p/zbar/code/ci/default/tree/include/zbar.h#l359>`__, the quality field is

  ...an unscaled, relative quantity: larger values are better than smaller
  values, where "large" and "small" are application dependent. Expect the exact
  definition of this quantity to change as the metric is refined. currently,
  only the ordered relationship between two values is defined and will remain
  stable in the future

Bounding boxes and polygons
---------------------------

The blue and pink boxes show ``rect`` and ``polygon``, respectively, for
barcodes in ``pyzbar/tests/qrcode.png`` (see
`bounding_box_and_polygon.py <https://github.com/NaturalHistoryMuseum/pyzbar/blob/master/bounding_box_and_polygon.py>`__).

.. figure:: https://github.com/NaturalHistoryMuseum/pyzbar/raw/master/bounding_box_and_polygon.png
   :alt: Two barcodes with bounding boxes and polygons

Windows error message
---------------------

If you see an ugly ``ImportError`` when importing ``pyzbar`` on Windows
you will most likely need the `Visual C++ Redistributable Packages for Visual
Studio 2013
<https://www.microsoft.com/en-US/download/details.aspx?id=40784>`__.
Install ``vcredist_x64.exe`` if using 64-bit Python, ``vcredist_x86.exe`` if
using 32-bit Python.

Contributors
------------

-  Alex (@globophobe) - first implementation of barcode locations
-  Dmytro Ferens (@dferens) - barcode orientation
-  Ismail Bento (@isman7) - support for images loaded using imageio
-  @jaant - read barcodes containing null characters

License
-------

``pyzbar`` is distributed under the MIT license (see ``LICENCE.txt``).
The ``zbar`` shared library is distributed under the
`GNU Lesser General Public License, version 2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NaturalHistoryMuseum/pyzbar/",
    "name": "pyzbar",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Lawrence Hudson",
    "author_email": "quicklizard@googlemail.com",
    "download_url": "",
    "platform": null,
    "description": "pyzbar\n======\n\n.. image:: https://img.shields.io/badge/python-2.7%2C%203.5%2C%203.6%2C%203.7%2C%203.8%2C%203.9%2C%203.10-blue.svg\n    :target: https://github.com/NaturalHistoryMuseum/pyzbar\n\n.. image:: https://badge.fury.io/py/pyzbar.svg\n    :target: https://pypi.python.org/pypi/pyzbar\n\n.. image:: https://img.shields.io/github/workflow/status/NaturalHistoryMuseum/pyzbar/Tests/master?label=tests\n    :target: https://github.com/NaturalHistoryMuseum/pyzbar/actions?query=workflow%3A%22Tests%22\n\n.. image:: https://coveralls.io/repos/github/NaturalHistoryMuseum/pyzbar/badge.svg?branch=master\n    :target: https://coveralls.io/github/NaturalHistoryMuseum/pyzbar?branch=master\n\nRead one-dimensional barcodes and QR codes from Python 2 and 3 using the\n`zbar <http://zbar.sourceforge.net/>`__ library.\n\n-  Pure python\n-  Works with PIL / Pillow images, OpenCV / imageio / numpy ``ndarray``\\ s, and raw bytes\n-  Decodes locations of barcodes\n-  No dependencies, other than the zbar library itself\n-  Tested on Python 2.7, and Python 3.5 to 3.10\n\nThe older `zbar <https://sourceforge.net/p/zbar/code/ci/default/tree/python/>`__\npackage is stuck in Python 2.x-land.\nThe `zbarlight <https://github.com/Polyconseil/zbarlight/>`__ package does not\nprovide support for Windows and depends upon Pillow.\n\nInstallation\n------------\n\nThe ``zbar`` DLLs are included with the Windows Python wheels.\nOn other operating systems, you will need to install the ``zbar`` shared\nlibrary.\n\nMac OS X:\n\n::\n\n   brew install zbar\n\nLinux:\n\n::\n\n   sudo apt-get install libzbar0\n\nInstall this Python wrapper; use the second form to install dependencies of the\ncommand-line scripts:\n\n::\n\n   pip install pyzbar\n   pip install pyzbar[scripts]\n\nExample usage\n-------------\n\nThe ``decode`` function accepts instances of ``PIL.Image``.\n\n::\n\n   >>> from pyzbar.pyzbar import decode\n   >>> from PIL import Image\n   >>> decode(Image.open('pyzbar/tests/code128.png'))\n   [\n       Decoded(\n           data=b'Foramenifera', type='CODE128',\n           rect=Rect(left=37, top=550, width=324, height=76),\n           polygon=[\n               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),\n               Point(x=361, y=550)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n       Decoded(\n           data=b'Rana temporaria', type='CODE128',\n           rect=Rect(left=4, top=0, width=390, height=76),\n           polygon=[\n               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),\n               Point(x=394, y=0)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n   ]\n\nIt also accepts instances of ``numpy.ndarray``, which might come from loading\nimages using `OpenCV <http://opencv.org/>`__.\n\n::\n\n   >>> import cv2\n   >>> decode(cv2.imread('pyzbar/tests/code128.png'))\n   [\n       Decoded(\n           data=b'Foramenifera', type='CODE128',\n           rect=Rect(left=37, top=550, width=324, height=76),\n           polygon=[\n               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),\n               Point(x=361, y=550)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n       Decoded(\n           data=b'Rana temporaria', type='CODE128',\n           rect=Rect(left=4, top=0, width=390, height=76),\n           polygon=[\n               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),\n               Point(x=394, y=0)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n   ]\n\nYou can also provide a tuple ``(pixels, width, height)``, where the image data\nis eight bits-per-pixel.\n\n::\n\n   >>> image = cv2.imread('pyzbar/tests/code128.png')\n   >>> height, width = image.shape[:2]\n\n   >>> # 8 bpp by considering just the blue channel\n   >>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height))\n   [\n       Decoded(\n           data=b'Foramenifera', type='CODE128',\n           rect=Rect(left=37, top=550, width=324, height=76),\n           polygon=[\n               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),\n               Point(x=361, y=550)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n       Decoded(\n           data=b'Rana temporaria', type='CODE128',\n           rect=Rect(left=4, top=0, width=390, height=76),\n           polygon=[\n               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),\n               Point(x=394, y=0)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n   ]\n\n   >>> # 8 bpp by converting image to greyscale\n   >>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n   >>> decode((grey.tobytes(), width, height))\n   [\n       Decoded(\n           data=b'Foramenifera', type='CODE128',\n           rect=Rect(left=37, top=550, width=324, height=76),\n           polygon=[\n               Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),\n               Point(x=361, y=550)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n       Decoded(\n           data=b'Rana temporaria', type='CODE128',\n           rect=Rect(left=4, top=0, width=390, height=76),\n           polygon=[\n               Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),\n               Point(x=394, y=0)\n           ],\n           orientation=\"UP\",\n           quality=77\n       )\n   ]\n\n   >>> # If you don't provide 8 bpp\n   >>> decode((image.tobytes(), width, height))\n   Traceback (most recent call last):\n     File \"<stdin>\", line 1, in <module>\n     File \"/Users/lawh/projects/pyzbar/pyzbar/pyzbar.py\", line 102, in decode\n       raise PyZbarError('Unsupported bits-per-pixel [{0}]'.format(bpp))\n   pyzbar.pyzbar_error.PyZbarError: Unsupported bits-per-pixel [24]\n\nThe default behaviour is to decode all symbol types. You can look for just your\nsymbol types\n\n::\n\n   >>> from pyzbar.pyzbar import ZBarSymbol\n   >>> # Look for just qrcode\n   >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.QRCODE])\n   [\n       Decoded(\n           data=b'Thalassiodracon', type='QRCODE',\n           rect=Rect(left=27, top=27, width=145, height=145),\n           polygon=[\n               Point(x=27, y=27), Point(x=27, y=172), Point(x=172, y=172),\n               Point(x=172, y=27)\n           ],\n           orientation=\"UP\",\n           quality=1\n       )\n   ]\n\n\n   >>> # If we look for just code128, the qrcodes in the image will not be detected\n   >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128])\n   []\n\nZBar versions\n-------------\n\nDevelopment of the `original zbar <http://zbar.sourceforge.net/>`__ stopped in 2012.\nDevelopment was started again in 2019 under a `new project <https://github.com/mchehab/zbar/>`__\nthat has added some new features, including support for decoding\nbarcode orientation. At the time of writing this new project does not produce Windows DLLs.\nThe ``zbar`` DLLs that are included with the Windows Python wheels are built from the original\nproject and so do not include support for decoding barcode orientation.\nIf you see ``orientation=None`` then your system has an older release of zbar that does\nnot support orientation.\n\nQuality field\n-------------\nFrom\n`zbar.h <https://sourceforge.net/p/zbar/code/ci/default/tree/include/zbar.h#l359>`__, the quality field is\n\n  ...an unscaled, relative quantity: larger values are better than smaller\n  values, where \"large\" and \"small\" are application dependent. Expect the exact\n  definition of this quantity to change as the metric is refined. currently,\n  only the ordered relationship between two values is defined and will remain\n  stable in the future\n\nBounding boxes and polygons\n---------------------------\n\nThe blue and pink boxes show ``rect`` and ``polygon``, respectively, for\nbarcodes in ``pyzbar/tests/qrcode.png`` (see\n`bounding_box_and_polygon.py <https://github.com/NaturalHistoryMuseum/pyzbar/blob/master/bounding_box_and_polygon.py>`__).\n\n.. figure:: https://github.com/NaturalHistoryMuseum/pyzbar/raw/master/bounding_box_and_polygon.png\n   :alt: Two barcodes with bounding boxes and polygons\n\nWindows error message\n---------------------\n\nIf you see an ugly ``ImportError`` when importing ``pyzbar`` on Windows\nyou will most likely need the `Visual C++ Redistributable Packages for Visual\nStudio 2013\n<https://www.microsoft.com/en-US/download/details.aspx?id=40784>`__.\nInstall ``vcredist_x64.exe`` if using 64-bit Python, ``vcredist_x86.exe`` if\nusing 32-bit Python.\n\nContributors\n------------\n\n-  Alex (@globophobe) - first implementation of barcode locations\n-  Dmytro Ferens (@dferens) - barcode orientation\n-  Ismail Bento (@isman7) - support for images loaded using imageio\n-  @jaant - read barcodes containing null characters\n\nLicense\n-------\n\n``pyzbar`` is distributed under the MIT license (see ``LICENCE.txt``).\nThe ``zbar`` shared library is distributed under the\n`GNU Lesser General Public License, version 2.1 <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>`__\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Read one-dimensional barcodes and QR codes from Python 2 and 3.",
    "version": "0.1.9",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "688891efc88324c783e8325ea54cf03b",
                "sha256": "4559628b8192feb25766d954b36a3753baaf5c97c03135aec7e4a026036b475d"
            },
            "downloads": -1,
            "filename": "pyzbar-0.1.9-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "688891efc88324c783e8325ea54cf03b",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 32560,
            "upload_time": "2022-03-15T14:53:40",
            "upload_time_iso_8601": "2022-03-15T14:53:40.637093Z",
            "url": "https://files.pythonhosted.org/packages/6d/24/81ebe6a1c00760471a3028a23cbe0b94e5fa2926e5ba47adc895920887bc/pyzbar-0.1.9-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d407c9f3e1753653dd35ddce23a6c9d2",
                "sha256": "8f4c5264c9c7c6b9f20d01efc52a4eba1ded47d9ba857a94130afe33703eb518"
            },
            "downloads": -1,
            "filename": "pyzbar-0.1.9-py2.py3-none-win32.whl",
            "has_sig": false,
            "md5_digest": "d407c9f3e1753653dd35ddce23a6c9d2",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 810633,
            "upload_time": "2022-03-15T14:53:43",
            "upload_time_iso_8601": "2022-03-15T14:53:43.446236Z",
            "url": "https://files.pythonhosted.org/packages/8e/87/7b596730179ddf17857eea33ba820354dd4e1cf941e57f51ffccce26c409/pyzbar-0.1.9-py2.py3-none-win32.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "1a5386055051807667c07ad562a1835c",
                "sha256": "13e3ee5a2f3a545204a285f41814d5c0db571967e8d4af8699a03afc55182a9c"
            },
            "downloads": -1,
            "filename": "pyzbar-0.1.9-py2.py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "1a5386055051807667c07ad562a1835c",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 817363,
            "upload_time": "2022-03-15T14:53:46",
            "upload_time_iso_8601": "2022-03-15T14:53:46.691976Z",
            "url": "https://files.pythonhosted.org/packages/0a/e2/1c6a8e94197612dbdfc51eab8dfb674168829885fac2c4f50ac8366c25ca/pyzbar-0.1.9-py2.py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-15 14:53:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "NaturalHistoryMuseum",
    "github_project": "pyzbar",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "pyzbar"
}
        
Elapsed time: 0.01736s