Giter VIP home page Giter VIP logo

pyzbar's Introduction

pyzbar

https://img.shields.io/github/workflow/status/NaturalHistoryMuseum/pyzbar/Tests/master?label=tests https://coveralls.io/repos/github/NaturalHistoryMuseum/pyzbar/badge.svg?branch=master

Read one-dimensional barcodes and QR codes from Python 2 and 3 using the zbar library.

  • Pure python
  • Works with PIL / Pillow images, OpenCV / imageio / numpy ndarrays, 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 package is stuck in Python 2.x-land. The 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.

>>> 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 stopped in 2012. Development was started again in 2019 under a new project 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, 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).

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. 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

pyzbar's People

Contributors

dferens avatar globophobe avatar isman7 avatar quicklizard99 avatar tirkarthi 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyzbar's Issues

Feature request: Add "quality" field to Decoded

I use console tool zbarimg to parse barcodes. It produces the following output:

zbarimg --xml orig.jpeg
<barcodes xmlns='http://zbar.sourceforge.net/2008/barcode'>
<source href='orig.jpeg'>
<index num='0'>
<symbol type='EAN-13' quality='3'><data><![CDATA[8601175003005]]></data></symbol>
<symbol type='EAN-13' quality='127'><data><![CDATA[4607096003005]]></data></symbol>
</index>

I want to get quality field in pyzbar to throw out low-quality matches, but decode function returns the following:

[Decoded(data=b'8601175003005', type='EAN13', rect=Rect(left=211, top=860, width=165, height=3), polygon=[Point(x=211, y=861), Point(x=211, y=863), Point(x=376, y=860)]), Decoded(data=b'4607096003005', type='EAN13', rect=Rect(left=54, top=785, width=323, height=127), polygon=[Point(x=54, y=785), Point(x=54, y=853), Point(x=55, y=909), Point(x=220, y=912), Point(x=376, y=912), Point(x=377, y=850), Point(x=377, y=786)])]

Is it possible to add quality field to Decoded items?

detection of barcodes of 0 size

When I execute the code it detects a bar code of zero size, e.g:

[Decoded(data=b'045398', type='I25', rect=Rect(left=1430, top=959, width=0, height=0), polygon=[Point(x=1430, y=959)])]

And this is an invalid barcode that doesn't really appear in the image

ImportError: Unable to find zbar shared library

after pip install pyzbar, I've test it in python3.4 and python3.6

import pyzbar
from pyzbar.pyzbar import decode
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.6/site-packages/pyzbar/pyzbar.py", line 7, in
from .wrapper import (
File "/usr/lib/python3.6/site-packages/pyzbar/wrapper.py", line 148, in
c_uint_p, # minor
File "/usr/lib/python3.6/site-packages/pyzbar/wrapper.py", line 141, in zbar_function
return prototype((fname, load_libzbar()))
File "/usr/lib/python3.6/site-packages/pyzbar/wrapper.py", line 120, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "/usr/lib/python3.6/site-packages/pyzbar/zbar_library.py", line 65, in load
raise ImportError('Unable to find zbar shared library')
ImportError: Unable to find zbar shared library

what's the problem?!

ZBarConfig enum Usage

Hello,

Is there a way to use ZBarConfig enums, like ZBarConfig.CFG_X_DENSITY ?

Thanks in advance for your reply.

Minimum resolution required

What is the minimum resolution which is required for PyZbar to be able to decode a barcode?
Moreover, does it do any contrast maximization inside or it should be done as a pre-processing?

Failed to load dynlib/dll libiconv.dll

I am using pyinstaller script to pack my program. The pyinstaller script run without errors. However, when I ran my exe file which is produced by pyinstaller script, I got the error:
main.PyInstallerImportError: Failed to load dynlib/dll 'C:\Users\evyin\AppData\Local\Temp\_MEI18~1\pyzbar\libiconv.dll'. Most probably this dynlib/dll was not found when the application was frozen.
My environment: Python 3.5, win10 64bit

new 'rect' attribute issues (Multiple)

Version sync issue (I think)

If you do:
'pip install pyzbar'

you do not the latest pyzbar version that contains the 'rect' locations stuff

If you manually do an install with something like:
'pip install https://github.com/NaturalHistoryMuseum/pyzbar.git'

you will have missing dependencies for the dll files 'libiconv' and 'libzbar'

I think this is a minor issue, but it was kind of annoying.

How to get around this issue for noobs such as myself:

  1. Do a (fresh) 'pip install pyzbar'
  2. Then I copied the dll files from my 'C:\Users<USERNAME>\Anaconda3\Lib\site-packages\pyzbar'
  3. 'pip uninstall pyzbar', to get rid of the version that did not contain the 'rect' changes
  4. 'pip install pyzbar' , then proceed to copy the dll files back into the '/site-packages/pyzbar' folder

800x1400 failed

HI, I test a jpg file of 800x1400 (w*h), but it can't find the qrcode.
when I take the ROI of 500x1000 from the same file ,it worked. why?

attribute error:'list' object has no attribute 'rect'

error:
Traceback (most recent call last):
File "C:/Users/Dell/Projects/open_cv/test_barcode.py", line 94, in
x,y,w,h=barcodes.rect
AttributeError: 'list' object has no attribute 'rect'

Process finished with exit code 1

works not as good on linux

I want to decode a QR-Code in python with pyzbar.pyzbar.decode. On Windows it works perfectly fine, but on Linux (Ubuntu) there show nothing. No Error, only an empty array.

Decoding umlauts

The zbar library obviously has problems with data containing non-ascii symbols, eg. german umlauts (ä ö ü).

I tried to decode the longer text from the QR-Code at https://de.wikipedia.org/wiki/QR-Code.

The result is:
b'Wikipedia ist ein Projekt zum Aufbau einer Enzyklop\xef\xbe\x83\xef\xbd\xa4die aus freien Inhalten in \xef\xbe\x83\xef\xbd\xbcber 270 Sprachen, zu dem du mit deinem Wissen beitragen kannst.'

This should be "Enzyklopädie" and "in über 270 Sprache".

Trying to decode with utf-8, this gives:

'Wikipedia ist ein Projekt zum Aufbau einer Enzyklopテ、die aus freien Inhalten in テシber 270 Sprachen, zu dem du mit deinem Wissen beitragen kannst.'

This does the trick: decode with utf-8, encode with shift-jis, and then decode with utf-8 again:

data.decode("utf-8").encode("shift-jis").decode("utf-8")
'Wikipedia ist ein Projekt zum Aufbau einer Enzyklopädie aus freien Inhalten in über 270 Sprachen, zu dem du mit deinem Wissen beitragen kannst.'

I thought I'll add this as an issue to help others.

Max resolution limit ?

Hi,

In my tests, max input image resolution limited to 2000x2000. Where this limit may coming from? I was hoping to feed 10K*10K images for qrcode detection.
Thanks,

multiple barcodes

#Hi I'm trying to get datas from image with multiple barcodes

from pyzbar.pyzbar import decode
from PIL import Image

img_filename = "image with multiple barcodes"
image = Image.open(img_filename)
result = decode(image)
for item in result:
print(item.data)

#and what it prints is

b'2TFUP633'
b'655'
b'MJQ-741327JQD'
b'MJQ-741178JQD'
b'THRA-0459'
b'THRA-0383(A)'
b'SH1450'
b'SH1449AMQ'
b'H8-22'
b'H8-21'
b'IN-YO2020FW'
b'IN-YO6266'
b'IN-SY6070FW'

#but when it comes to using item.data for further processing,
#it only reads the last result "b'IN-SY6070FW'"

#is there any way to, for example, let item.data1 be first result's data, item.data2 be second result's data, and furthere for 3,4,5,6~?

#Thanks!

Support older numpy

numpy.ndarray.tobytes() was introduced in numpy 1.9.0. Use numpy.ndarray.tostring() where tobytes is not present.

Tidying

A few things need some love - README, pep8, docstrings

WARNING issue.

Hello, I frequently get the error message below. Suppressing by python error handler doesnt help. Why do you think this faults happening? They interrupt outputs on the terminal.

WARNING: .\zbar\decoder\pdf417.c:89: : Assertion "g[0] >= 0 && g[1] >= 0 && g[2] >= 0" failed.
dir=0 sig=2768 k=6 g0=ffffffff g1=fc8 g2=134 buf[0000]=

Where is the data in the project?

First of all, sorry to ask such a simple question. I'm in a hurry to find the all data with binary. The whole pyzbar is a big project, and I have spent half past month to find it but no progress yet indeed. The reason why I want to find the real data is that I did something in the encoding process of QRcode, and now I should decode QRcode to get the data before analyze it. I know the decode function in pyzbar.py will return the results include data. I have found that _pixel_data function returns pixel, height and width as the following picture.
image
Then I use debugger to found the data, but it's sad that I didn't found the all data in debugger. There are too many new things that I couldn't understand in a short time. Where is the all binary data in the project? Does the following picture realize that translate the binary data into character data? If not ,where should I find the binary data?
image
I am deeply appreciate any help from you!
PS: a debugger picture that I lost in
image

Installation of Zbar Library in AWS EC2

Zbar library successfully installed in MAC OS and pyzbar as well. However, when I tried to deploy in AWS, there is an issues. My OS is Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type - ami-09b42976632b27e9b.

My zbar files in my ec2-directory: /home/ec2-user/app/zbar/zbar-0.10
When I run ./configure, I have following error:
(venv) [ec2-user@ip-xx-xx-xx-xx zbar-0.10]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... Invalid configuration x86_64-unknown-linux-': machine x86_64-unknown-linux' not recognized
configure: error: /bin/sh config/config.sub x86_64-unknown-linux- failed

How to show only data

Is it possible to print only the data value from the decoded QR code?

I'm doing this:

from pyzbar.pyzbar import decode
from PIL import Image

data = decode(Image.open('test.png'))
print(data)

And I'm receiving this:
[Decoded(data=b'Some data', type='QRCODE', rect=Rect(left=40, top=40, width=210, height=210))]

If I want just the "data" value what should I do?
Thanks in advance.

Make 1-D barcode scan orientation invariant

Currently, pyzbar cannot detect 1-D barcodes (CODE128) if they are not positioned vertically or horizontally in the image. I am right now working on detecting barcodes in package labels and handling is done by the user. In some cases, users hold packages at an angle.

My solution at the moment is to rotate the image in a for loop and decode different orientations (rotation by 30, 60 degrees mainly). This approach is very slow and inefficient.

example

decode(image.rotate(30))

It will be great if there was a way pyzbar could handle this internally and more efficiently

Any thoughts on how this might be accomplished?

QR code orientation

Hi Author,
Thanks for the amazing work. Is there a way I can get info of the orientation of QR code?

Thanks!

Detection of Identical Barcodes in an image

Hi, is there any additional argument or parameters which can be passed to the decode function that will allow for identical barcodes found in an image to be N number of Decoded data?

As of now, only 1 Decoded result was shown when I was trying to decode the attached image. Thanks
IMG_20190309_152524

OSError: [WinError 126] Cannot find the specified module.

I have successfully use the command pip install pyzbar and installed it, but when I type from pyzbar.pyzbar import decode, I get the following error:OSError: [WinError 126] Cannot find the specified module.

The whole info is as follows:

OSError Traceback (most recent call last)
c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in load_libzbar()
127 try:
--> 128 loaded_dependencies, libzbar = load(Path(''))
129 except OSError as e:

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in load(dir)
121 cdll.LoadLibrary(str(dir.joinpath(dep)))
--> 122 for dep in dependencies
123 ]

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in (.0)
121 cdll.LoadLibrary(str(dir.joinpath(dep)))
--> 122 for dep in dependencies
123 ]

c:\users\acer\appdata\local\programs\python\python36\lib\ctypes_init_.py in LoadLibrary(self, name)
425 def LoadLibrary(self, name):
--> 426 return self._dlltype(name)
427

c:\users\acer\appdata\local\programs\python\python36\lib\ctypes_init_.py in init(self, name, mode, handle, use_errno, use_last_error)
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:

OSError: [WinError 126] 找不到指定的模块。

During handling of the above exception, another exception occurred:

OSError Traceback (most recent call last)
in ()
----> 1 from pyzbar.pyzbar import decode

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\pyzbar.py in ()
6
7 from .pyzbar_error import PyZbarError
----> 8 from .wrapper import (
9 zbar_image_scanner_set_config,
10 zbar_image_scanner_create, zbar_image_scanner_destroy,

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in ()
164 c_int,
165 c_uint_p, # major,
--> 166 c_uint_p, # minor
167 )
168

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in zbar_function(fname, restype, *args)
157 """
158 prototype = CFUNCTYPE(restype, *args)
--> 159 return prototype((fname, load_libzbar()))
160
161

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in load_libzbar()
128 loaded_dependencies, libzbar = load(Path(''))
129 except OSError as e:
--> 130 loaded_dependencies, libzbar = load(Path(file).parent)
131 else:
132 # Assume a shared library on the path

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in load(dir)
120 deps = [
121 cdll.LoadLibrary(str(dir.joinpath(dep)))
--> 122 for dep in dependencies
123 ]
124 libzbar = cdll.LoadLibrary(str(dir.joinpath(fname)))

c:\users\acer\appdata\local\programs\python\python36\lib\site-packages\pyzbar-0.1.4-py3.6.egg\pyzbar\wrapper.py in (.0)
120 deps = [
121 cdll.LoadLibrary(str(dir.joinpath(dep)))
--> 122 for dep in dependencies
123 ]
124 libzbar = cdll.LoadLibrary(str(dir.joinpath(fname)))

c:\users\acer\appdata\local\programs\python\python36\lib\ctypes_init_.py in LoadLibrary(self, name)
424
425 def LoadLibrary(self, name):
--> 426 return self._dlltype(name)
427
428 cdll = LibraryLoader(CDLL)

c:\users\acer\appdata\local\programs\python\python36\lib\ctypes_init_.py in init(self, name, mode, handle, use_errno, use_last_error)
346
347 if handle is None:
--> 348 self._handle = _dlopen(self._name, mode)
349 else:
350 self._handle = handle

OSError: [WinError 126] 找不到指定的模块。

error in rect from Decoded

After decoding a barcode from an Image,
I made further process where PIL draws a rectangle around the decoded barcode.
mostly it works, except sometime the value of rect(width) is zero, but the decoded data is correct.
example is attached.

from PIL import Image, ImageDraw
from pyzbar.pyzbar import decode
from pyzbar.pyzbar import Decoded

image = Image.open(r'e:/test1.png')
result = decode(image)
num = len(result)
i=0

while i < num:
resulti = result[i]
draw = ImageDraw.Draw(image)
x0i = resulti.rect[0]
y0i = resulti.rect[1]
x1i = x0i + resulti.rect[2]
y1i = y0i + resulti.rect[3]
drawrec = (x0i, y0i, x1i, y1i)
drawInrec = (x0i+1, y0i+1, x1i-1, y1i-1)
draw.rectangle(drawrec, fill=None, outline='red')
draw.rectangle(drawInrec, fill=None, outline='red')
print(i, resulti.data, resulti.rect)
i += 1
if i == num:
image.save(r'e:/test1.png')
image.show(r'e:/test1.png')

test1
testresult

Feature Request: Location/Position Support

I'm currently using zbar on Python 2.7 but in hopes of supporting Python 3 I checked out your library. It was very easy to get going, but unfortunately I use the location support in the zbar library to determine the location of QR codes in the image. I didn't see a way to do this with pyzbar. I looked into adding location support to the wrapper, but I was unable to get any location information out of libzbar itself in the python context. I tried both function signatures I expected to work as well as XML outputs.

Do you have any ideas on if it's possible to coax location information out of zbar in the context of this wrapper?

https://github.com/ZBar/ZBar/blob/master/python/symbol.c#L128

Failed to read bar code even with good quality images

Test url: https://samsung-nudge.s3.eu-central-1.amazonaws.com/20.jpeg

Current Behavior:
System is failing to read bar code in above image. Same problem is producing with other images too.
Expected Bar code : 0T315ADK600009E

Expected Behavior:
Able to read the bar code in above image.

Suggested Fix:
Having 0T315ADK600009E in result.

Used following function :

``

    def get_serialNumber(path):
         def barcode(im):
             decodedObjects = pyzbar.decode(im) 
             print(decodedObjects)
    
             for obj in decodedObjects:
                  barcode = 'Data : ', obj.data
    
             if decodedObjects == []:
                  return ""
             else:
                  return barcode

        im = cv2.imread(path)
        slno = barcode(im)

        if slno is "":
            return ""
        else:
           return slno[1].decode()

``

WinError 126 after building during execution *.exe

pyzbar 0.1.7
Python 3.4.4
py2exe 0.9.2.2

Traceback (most recent call last):
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 58, in load
dependencies, libzbar = load_objects(Path(''))
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 52, in load_objects
for dep in dependencies
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 52, in
for dep in dependencies
File "c:\python34\lib\ctypes_init_.py", line 429, in LoadLibrary
return self.dlltype(name)
File "c:\python34\lib\ctypes_init
.py", line 351, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] Das angegebene Modul wurde nicht gefunden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "RecIT.pyw", line 5, in
File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked
File "", line 1191, in _load_unlocked
File "", line 1161, in _load_backward_compatible
File "c:\python34\lib\site-packages\pyzbar\pyzbar.py", line 7, in
from .wrapper import (
File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked
File "", line 1191, in _load_unlocked
File "", line 1161, in load_backward_compatible
File "c:\python34\lib\site-packages\pyzbar\wrapper.py", line 148, in
c_uint_p, # minor
File "c:\python34\lib\site-packages\pyzbar\wrapper.py", line 141, in zbar_function
return prototype((fname, load_libzbar()))
File "c:\python34\lib\site-packages\pyzbar\wrapper.py", line 120, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 60, in load
dependencies, libzbar = load_objects(Path(file).parent)
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 52, in load_objects
for dep in dependencies
File "c:\python34\lib\site-packages\pyzbar\zbar_library.py", line 52, in
for dep in dependencies
File "c:\python34\lib\ctypes_init
.py", line 429, in LoadLibrary
return self.dlltype(name)
File "c:\python34\lib\ctypes_init
.py", line 351, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] Das angegebene Modul wurde nicht gefunden

attempted relative import with no known parent package

Platform: Windows10 64
Python: 3.6.6
Pip install

error occured when import

In [3]: from pyzbar.pyzbar import decode
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-95ae0761f4b5> in <module>()
----> 1 from pyzbar.pyzbar import decode

D:\bin\python\Lib\site-packages\pyzbar\pyzbar.py in <module>()
      3 from ctypes import cast, c_void_p, string_at
      4
----> 5 from .locations import bounding_box, convex_hull, Point, Rect
      6 from .pyzbar_error import PyZbarError
      7 from .wrapper import (

ImportError: attempted relative import with no known parent package

Add support to load library externally

As pyzbar is a very usable library to handle images, some applications wants to handle images in a very scalable context like serverless platforms (aws lambda, azure function and so on). These platforms run workloads on top of default environments that is not easy to customize to add a shared lib as pyzbar requires.

So, my suggestions is to add a new try during the load library function in pyzbar/zbar_library.py. The code below is showing only trying get the library in PATH, but a good try is find the library in a specific env var like ZBAR_PATH.

else:
        # Assume a shared library on the path
        path = find_library('zbar')
        if not path:
            path = os.environ.get('ZBAR_PATH')
            if not path: 
                raise ImportError('Unable to find zbar shared library')
        libzbar = cdll.LoadLibrary(path)
        dependencies = []

NameError: name 'Decoded' is not defined

decode(cv2.imread('pyzbar/tests/code128.png'))
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/site-packages/pyzbar/pyzbar.py", line 111, in decode
pixels, width, height = image
TypeError: 'NoneType' object is not iterable
[Decoded(data=b'Foramenifera', type='CODE128'),
... Decoded(data=b'Rana temporaria', type='CODE128')]
Traceback (most recent call last):
File "", line 1, in
NameError: name 'Decoded' is not defined

Adding HiQ and JABCode to the mix

Introduction

JABCode is a color barcode used by the German government (Federal Office of Information Security) for tagging items. Currently there is no easy-to-use solutions available for the public to test and experiment. It is written in C

HiQ is a color barcode based on QR code, created by the students Hong Kong Chinese University (the top University of Hong Kong). It is written in Java

Proposal

Inclusion of JABCode and HiQ color barcode creators and readers, and either add or adapt those repos into a neat Python package.

References

For JABCode

For HiQ

Too many values to unpack

>>> img = requests.get("https://liketomove.it/defi-qr/la_solution_c_est_pas_3.jpg")
>>> print(decode(img))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/thedevkiller/.local/lib/python3.6/site-packages/pyzbar/pyzbar.py", line 180, in decode
    pixels, width, height = _pixel_data(image)
  File "/home/thedevkiller/.local/lib/python3.6/site-packages/pyzbar/pyzbar.py", line 145, in _pixel_data
    pixels, width, height = image
ValueError: too many values to unpack (expected 3)

I also tried to download the file, same error

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.