Skip to content

Commit

Permalink
Merge pull request #8 from NaturalHistoryMuseum/feature/7-numpy-inter…
Browse files Browse the repository at this point in the history
…face

[#7] older numpy
  • Loading branch information
quicklizard99 authored Dec 1, 2016
2 parents ac8b92a + 9f96b35 commit d3c9bb9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### v0.1.3

* #7 Support older numpy

### v0.1.2

* #5 Better handling of DLLs
Expand Down
2 changes: 1 addition & 1 deletion pyzbar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""A ctypes-based wrapper around the zbar barcode reader."""

__version__ = '0.1.2'
__version__ = '0.1.3'
7 changes: 6 additions & 1 deletion pyzbar/pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def decode(image, symbols=None):
image = image[:, :, 0]
if 'uint8' != str(image.dtype):
image = image.astype('uint8')
pixels = image.tobytes()
try:
pixels = image.tobytes()
except AttributeError:
# `numpy.ndarray.tobytes()` introduced in `numpy` 1.9.0 - use the
# older `tostring` method.
pixels = image.tostring()
height, width = image.shape[:2]
else:
# image should be a tuple (pixels, width, height)
Expand Down
7 changes: 7 additions & 0 deletions pyzbar/tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from pathlib import Path

import numpy as np

from PIL import Image

try:
Expand Down Expand Up @@ -83,6 +85,11 @@ def test_empty(self):
expected = []
self.assertEqual(expected, res)

def test_decode_numpy(self):
"Read image using Pillow and convert to numpy.ndarray"
res = decode(np.asarray(self.code128))
self.assertEqual(self.EXPECTED_CODE128, res)

@unittest.skipIf(cv2 is None, 'OpenCV not installed')
def test_decode_opencv(self):
"Read image using OpenCV"
Expand Down
1 change: 1 addition & 0 deletions requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ enum34==1.1.6; python_version == '2.7'
# TODO How to specify OpenCV? 'cv2>=2.4.8'
coveralls>=1.1
nose>=1.3.4
numpy>=1.8.2
pathlib>=1.0.1; python_version == '2.7'
Pillow>=3.2.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def readme():
},
'tests_require': [
# TODO How to specify OpenCV? 'cv2>=2.4.8',
PILLOW
PILLOW,
'numpy>=1.8.2',
],
'include_package_data': True,
'classifiers': [
Expand Down

0 comments on commit d3c9bb9

Please sign in to comment.