From 4f5ec4a25241fcbf4312db9fd0547c56f64ebace Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Tue, 8 Nov 2016 12:52:18 +0000 Subject: [PATCH 01/11] [#27] Bump version --- gouda/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gouda/__init__.py b/gouda/__init__.py index c3bb296..1c98a23 100644 --- a/gouda/__init__.py +++ b/gouda/__init__.py @@ -1 +1 @@ -__version__ = '0.1.8' +__version__ = '0.1.9' From 40e0d5113365f3561f07d54bc050a7b6d9aaaca8 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Tue, 8 Nov 2016 12:52:27 +0000 Subject: [PATCH 02/11] [#27] CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0ca3fe..c77b90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v0.1.9 +- #27 Support pyzbar + # v0.1.8 - #24 Support pylibdmtx From 6da9309bf37af336e21134b27184f68748a16457 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Tue, 8 Nov 2016 12:52:59 +0000 Subject: [PATCH 03/11] [#27] Support pyzbar --- gouda/engines/zbar_engine.py | 27 +++++++++------------------ requirements.txt | 2 ++ setup.py | 1 + 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/gouda/engines/zbar_engine.py b/gouda/engines/zbar_engine.py index f28e0b2..a3f05f0 100644 --- a/gouda/engines/zbar_engine.py +++ b/gouda/engines/zbar_engine.py @@ -1,22 +1,22 @@ # This file is not called zbar.py to avoid collision with the zbar package -import cv2 - from gouda.barcode import Barcode from gouda.gouda_error import GoudaError from gouda.util import debug_print +from PIL import Image + try: - import zbar + from pyzbar import pyzbar except ImportError: - zbar = None + pyzbar = None class ZbarEngine(object): """Decode using the zbar library http://sourceforge.net/projects/zbar/ - https://pypi.python.org/pypi/zbar + https://pypi.python.org/pypi/pyzbar """ def __init__(self): if not self.available(): @@ -24,20 +24,11 @@ def __init__(self): @classmethod def available(cls): - return zbar is not None + return pyzbar is not None def decode_file(self, path): - return self(cv2.imread(str(path), cv2.IMREAD_GRAYSCALE)) + return self(Image.open(str(path))) def __call__(self, img): - # Decode barcodes in img using zbar - # https://github.com/ZBar/ZBar/blob/master/python/README - # https://github.com/herbyme/zbar/blob/master/python/examples/scan_image.py - scanner = zbar.ImageScanner() - height, width = img.shape[:2] - if 'uint8' != img.dtype or 2 != len(img.shape): - debug_print('Convert to greyscale for zbar') - img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) - image = zbar.Image(width, height, 'Y800', img.tostring()) - scanner.scan(image) - return [Barcode(str(s.type), unicode(s.data, 'utf8')) for s in image] + # Decode barcodes in img using pyzbar + return [Barcode(r.type, r.data) for r in pyzbar.decode(img)] diff --git a/requirements.txt b/requirements.txt index a737c7e..143d93d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ +# TODO How to specify OpenCV? 'cv2>=2.4.8', pathlib>=1.0 pylibdmtx>=0.1.1 +pyzbar>=0.1.1 numpy>=1.8.2 # Packages required for testing diff --git a/setup.py b/setup.py index f969ef3..79138a2 100755 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ # TODO How to specify OpenCV? 'cv2>=2.4.8,<3', 'pathlib>=1.0.1', 'pylibdmtx>=0.1.1', + 'pyzbar>=0.1.1', 'numpy>=1.8.2', ], 'tests_require': [ From 77d8917337fd9370820f1d4c37488e33cfdd4b3a Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 13:11:38 +0000 Subject: [PATCH 04/11] [#27] pyzbar and freeze --- MANIFEST.in | 3 ++- README.md | 4 ++-- decode_barcodes.spec | 26 ++++++++++++-------------- requirements.txt => requirements.pip | 9 ++++++--- 4 files changed, 22 insertions(+), 20 deletions(-) rename requirements.txt => requirements.pip (53%) diff --git a/MANIFEST.in b/MANIFEST.in index cd664b0..9bc3e07 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include *.py -include requirements.txt +include requirements.pip +include gouda/tests/test_data/*png diff --git a/README.md b/README.md index 593fee5..0acd7f9 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The easiest way is to install the current Python 2.7 release of conda update --all pip install --upgrade pip python \Scripts\pywin32_postinstall.py -install - pip install -r requirements.txt + pip install -r requirements.pip ## Install [OpenCV](http://www.opencv.org/) ### Linux @@ -98,7 +98,7 @@ Windows only. Download and install their [SDK](http://www.inliteresearch.com/). ### libdmtx The [pylibdmtx](https://pypi.python.org/pypi/pylibdmtx/) Python package is -a dependency of `gouda` and is listed in `requirements.txt`. +a dependency of `gouda` and is listed in `requirements.pip`. The `libdmtx` `DLL`s are included with the Windows Python wheel builds of `pylibdmtx`. diff --git a/decode_barcodes.spec b/decode_barcodes.spec index fe0762e..e73dc9a 100644 --- a/decode_barcodes.spec +++ b/decode_barcodes.spec @@ -1,9 +1,13 @@ -# For PyInstaller build on Mac +# For PyInstaller build import sys from pathlib import Path +from pylibdmtx import pylibdmtx +from pyzbar import pyzbar + + block_cipher = None a = Analysis(['gouda/scripts/decode_barcodes.py'], @@ -18,13 +22,14 @@ a = Analysis(['gouda/scripts/decode_barcodes.py'], win_private_assemblies=False, cipher=block_cipher) -if 'darwin' == sys.platform: - # libdmtx dylib is not detected because it is loaded by a ctypes call in - # pylibdmtx - a.binaries += TOC([ - ('libdmtx.dylib', '/usr/local/Cellar/libdmtx/0.7.4/lib/libdmtx.dylib', 'BINARY'), - ]) +# dylibs not detected because they are loaded by ctypes +a.binaries += TOC([ + (Path(dep._name).name, dep._name, 'BINARY') + for dep in pylibdmtx.EXTERNAL_DEPENDENCIES + pyzbar.EXTERNAL_DEPENDENCIES +]) + +if 'darwin' == sys.platform: # PyInstaller does not detect some dylibs, in some cases (I think) because they # are symlinked. # See Stack Overflow post http://stackoverflow.com/a/17595149 for example @@ -56,13 +61,6 @@ if 'darwin' == sys.platform: a.binaries += TOC([ (lib, str(LIB.joinpath(lib).resolve()), 'BINARY') for lib in MISSING_DYLIBS ]) -elif 'win32' == sys.platform: - # libdmtx dylib is not detected because it is loaded by a ctypes call in - # pylibdmtx - fname = 'libdmtx-{0}.dll'.format('64' if sys.maxsize > 2**32 else '32') - a.binaries += TOC([ - (fname, str(Path(sys.argv[0]).parent.parent.joinpath(fname)), 'BINARY'), - ]) pyz = PYZ(a.pure, a.zipped_data, diff --git a/requirements.txt b/requirements.pip similarity index 53% rename from requirements.txt rename to requirements.pip index 143d93d..3a053d0 100644 --- a/requirements.txt +++ b/requirements.pip @@ -1,9 +1,12 @@ # TODO How to specify OpenCV? 'cv2>=2.4.8', -pathlib>=1.0 -pylibdmtx>=0.1.1 -pyzbar>=0.1.1 +pathlib>=1.0.1 +pylibdmtx==0.1.4 +pyzbar==0.1.2 numpy>=1.8.2 # Packages required for testing coveralls>=1.1 nose>=1.3.4 + +# Packages required for distribution +PyInstaller==3.1.1 From c22d1c8088d1457d508eeeb9d33dc8134b836833 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 13:11:55 +0000 Subject: [PATCH 05/11] [#27] Prefer wheel to sdist --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 8a91d66..c705021 100755 --- a/build.sh +++ b/build.sh @@ -15,5 +15,5 @@ echo Tests nosetests --with-coverage --cover-html --cover-inclusive --cover-erase --cover-tests --cover-package=gouda echo Build -./setup.py sdist +./setup.py bdist pyinstaller --onefile --clean decode_barcodes.spec From 7916e78eafe3afc0b082a9d6560c7a3603e8f85b Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 13:14:15 +0000 Subject: [PATCH 06/11] [#27] libzbar and requirements.pip --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d24fbcb..fbe7bec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,11 @@ virtualenv: install: - sudo apt-get -qq update - - sudo apt-get install -y --fix-missing libdmtx0a python-opencv - - pip install -r requirements.txt + - sudo apt-get install -y --fix-missing libdmtx0a libzbar0 python-opencv + - pip install -r requirements.pip script: -- nosetests + - nosetests after_success: - coveralls From b616e173d8ffd16e5f0993f8bf2dcb452da5e22f Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 13:53:22 +0000 Subject: [PATCH 07/11] Pillow --- requirements.pip | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.pip b/requirements.pip index 3a053d0..47d1e46 100644 --- a/requirements.pip +++ b/requirements.pip @@ -1,5 +1,6 @@ # TODO How to specify OpenCV? 'cv2>=2.4.8', pathlib>=1.0.1 +Pillow>=3.2.0 pylibdmtx==0.1.4 pyzbar==0.1.2 numpy>=1.8.2 From 29ac40f31392edbadc0a07837e76179e692370fe Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 14:03:01 +0000 Subject: [PATCH 08/11] IMREAD_UNCHANGED not present OpenCV < 2.4.0; Travis CI is currently on OpenCV 2.3 --- gouda/util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gouda/util.py b/gouda/util.py index 534b485..458fb8a 100644 --- a/gouda/util.py +++ b/gouda/util.py @@ -22,8 +22,10 @@ def debug_print(*args, **kwargs): def read_image(path, greyscale): - flags = cv2.IMREAD_GRAYSCALE if greyscale else cv2.IMREAD_UNCHANGED - return cv2.imread(str(path), flags) + if greyscale: + return cv2.imread(str(path), cv2.IMREAD_GRAYSCALE) + else: + return cv2.imread(str(path)) def expand_wildcard(args): From a089cf4421a84c398884f7ab652fd73106e48ffd Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 14:09:07 +0000 Subject: [PATCH 09/11] Predictable order of processing files --- gouda/scripts/decode_barcodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gouda/scripts/decode_barcodes.py b/gouda/scripts/decode_barcodes.py index 706b8b5..a79751c 100755 --- a/gouda/scripts/decode_barcodes.py +++ b/gouda/scripts/decode_barcodes.py @@ -26,7 +26,7 @@ def decode(paths, strategies, engine, visitors, read_greyscale): """Finds and decodes barcodes in images given in pathss """ - for p in paths: + for p in sorted(paths): if p.is_dir(): # Descend into directory decode(p.iterdir(), strategies, engine, visitors, read_greyscale) From 8df8c0cf813c9b52c4dc242713eb445990077638 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 14:23:25 +0000 Subject: [PATCH 10/11] Wheel --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index c705021..caf219e 100755 --- a/build.sh +++ b/build.sh @@ -15,5 +15,5 @@ echo Tests nosetests --with-coverage --cover-html --cover-inclusive --cover-erase --cover-tests --cover-package=gouda echo Build -./setup.py bdist +./setup.py bdist_wheel pyinstaller --onefile --clean decode_barcodes.spec From a5f47bbfc7387b5d4bee3faf85b036847e9caa2f Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Wed, 9 Nov 2016 15:44:55 +0000 Subject: [PATCH 11/11] Coverage --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fbe7bec..d6626fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - pip install -r requirements.pip script: - - nosetests + - python -m nose --verbose --with-coverage --cover-inclusive --cover-tests --cover-package=gouda gouda after_success: - coveralls