Skip to content
This repository has been archived by the owner on Sep 15, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/20190223'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Feb 22, 2019
2 parents 16d960a + abf1d8d commit f146e68
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 37 deletions.
25 changes: 15 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Change Log

## [20190223]

- Fix zbarlight dependency in setup.py, refs #28
- Migrate to zbarlight 2.1, refs #18

## [20190222]

- Provide Makefile, refs #15
- Setup continuous integration testing, refs #6, #14
- Speedup OpenCV compilation time, refs #16
- Migrated to zbarlight, refs #5, #13
- Introduced UI tests, refs #4
- Using non-root Docker container, refs #27
- Run UI tests from Travis, refs #26
- Provide Makefile, refs #15
- Setup continuous integration testing, refs #6, #14
- Speedup OpenCV compilation time, refs #16
- Migrated to zbarlight, refs #5, #13
- Introduced UI tests, refs #4
- Using non-root Docker container, refs #27
- Run UI tests from Travis, refs #26

## [20171220]

- Full screen camera
- Kvlang refactoring
- File tree refactoring
- Full screen camera
- Kvlang refactoring
- File tree refactoring

## [20171117]

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ test:

uitest: virtualenv
$(PIP) install -r requirements/test_requirements.txt
$(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/
$(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/ui/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ BoxLayout:
Label:
size_y: 20
size_hint_y: None
text: ", ".join([str(symbol.data) for symbol in zbarcam.symbols])
text: ", ".join([str(code) for code in zbarcam.codes])
```
## Install
Expand Down
1 change: 0 additions & 1 deletion __init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ version.filename = %(source.dir)s/zbarcam/version.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy, pil, libiconv, libzbar, zbarlight==1.2
requirements = kivy, pil, libiconv, libzbar, zbarlight>=2.1
# (str) Custom source folders for requirements
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zbarlight==1.2
zbarlight==2.2
Kivy==1.10.1
Kivy-Garden==0.1.4
Pillow==4.3.0
Expand Down
1 change: 1 addition & 0 deletions requirements/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
isort==4.2.5
flake8==3.3.0
mock==2.0.0
pytest==4.3.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
url='https://github.com/AndreMiras/garden.zbarcam',
packages=['zbarcam'],
package_data={'zbarcam': ['*.kv']},
install_requires=['zbar', 'kivy', 'pillow', 'numpy'])
install_requires=['zbarlight>=2.1', 'kivy', 'pillow', 'numpy'])
Binary file added tests/fixtures/no_qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/one_qr_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/one_qr_code_and_one_ean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/two_qr_codes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions tests/test_zbarcam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
import unittest

import mock
from kivy.base import EventLoop
from kivy.core.image import Image

from zbarcam import ZBarCam

FIXTURE_DIR = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'fixtures')
# https://github.com/kivy/kivy/blob/1.10.1/doc/sources/faq.rst
EventLoop.ensure_window()


class TestZBarCam(unittest.TestCase):

def setUp(self):
with mock.patch('kivy.uix.anchorlayout.AnchorLayout.__init__'):
self.zbarcam = ZBarCam()

def test_detect_qrcode_frame_no_qrcode(self):
"""
Checks `_detect_qrcode_frame()` returns empty list on no qrcode.
"""
fixture_path = os.path.join(FIXTURE_DIR, 'no_qr_code.png')
texture = Image(fixture_path).texture
code_types = self.zbarcam.code_types
symbols = self.zbarcam._detect_qrcode_frame(texture, code_types)
self.assertEqual(symbols, [])

def test_detect_qrcode_frame_one_qrcode(self):
"""
Checks `_detect_qrcode_frame()` can detect one qrcode.
"""
fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code.png')
texture = Image(fixture_path).texture
code_types = self.zbarcam.code_types
symbols = self.zbarcam._detect_qrcode_frame(texture, code_types)
self.assertEqual(
symbols,
['zbarlight test qr code'])

def test_detect_qrcode_frame_one_qrcode_one_ean(self):
"""
Checks `_detect_qrcode_frame()` can detect one qrcode and one ean.
"""
fixture_path = os.path.join(FIXTURE_DIR, 'one_qr_code_and_one_ean.png')
texture = Image(fixture_path).texture
code_types = self.zbarcam.code_types
symbols = self.zbarcam._detect_qrcode_frame(texture, code_types)
# currently detects no codes, but that's a bug
self.assertEqual(symbols, [])

def test_detect_qrcode_frame_two_qrcodes(self):
"""
Checks `_detect_qrcode_frame()` can detect two qrcodes.
"""
fixture_path = os.path.join(FIXTURE_DIR, 'two_qr_codes.png')
texture = Image(fixture_path).texture
code_types = self.zbarcam.code_types
symbols = self.zbarcam._detect_qrcode_frame(texture, code_types)
self.assertEqual(
symbols,
['second zbarlight test qr code', 'zbarlight test qr code']
)
File renamed without changes.
Empty file added tests/ui/__init__.py
Empty file.
File renamed without changes.
17 changes: 15 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
[tox]
envlist = pep8,isort-check
envlist = pep8,isort-check,py2
# no setup.py to be ran
skipsdist = True
# trick to enable pre-installation of Cython
# https://stackoverflow.com/a/50081741/185510
indexserver =
preinstall = https://pypi.python.org/simple

[testenv]
setenv = KIVY_UNITTEST = 1
passenv = DISPLAY
deps =
:preinstall: Cython==0.26.1
-r{toxinidir}/requirements/requirements.txt
-r{toxinidir}/requirements/test_requirements.txt
commands = pytest --ignore tests/ui/ tests/

[testenv:pep8]
deps =
-r{toxinidir}/requirements/test_requirements.txt
commands = flake8 zbarcam/ tests/

[testenv:isort-check]
deps =
-r{toxinidir}/requirements/test_requirements.txt
commands =
isort --check-only --recursive zbarcam/ tests/
isort --check-only --recursive --diff zbarcam/ tests/
2 changes: 1 addition & 1 deletion zbarcam/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2019.0222'
__version__ = '2019.0223'
26 changes: 8 additions & 18 deletions zbarcam/zbarcam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from collections import namedtuple

import PIL
import zbarlight
Expand Down Expand Up @@ -27,12 +26,11 @@
class ZBarCam(AnchorLayout):
"""
Widget that use the Camera and zbar to detect qrcode.
When found, the `symbols` will be updated.
When found, the `codes` will be updated.
"""
resolution = ListProperty([640, 480])

symbols = ListProperty([])
Symbol = namedtuple('Symbol', ['type', 'data'])
codes = ListProperty([])
# checking all possible types by default
code_types = ListProperty(zbarlight.Symbologies.keys())

Expand Down Expand Up @@ -74,10 +72,11 @@ def _enable_android_autofocus(self):
camera.setParameters(params)

def _on_texture(self, instance):
self._detect_qrcode_frame(
instance=None, camera=instance, texture=instance.texture)
self.codes = self._detect_qrcode_frame(
texture=instance.texture, code_types=self.code_types)

def _detect_qrcode_frame(self, instance, camera, texture):
@staticmethod
def _detect_qrcode_frame(texture, code_types):
image_data = texture.pixels
size = texture.size
fmt = texture.colorfmt.upper()
Expand All @@ -87,16 +86,7 @@ def _detect_qrcode_frame(self, instance, camera, texture):
if platform == 'ios' and fmt == 'BGRA':
fmt = 'RGBA'
pil_image = PIL.Image.frombytes(mode=fmt, size=size, data=image_data)
# calling `zbarlight.scan_codes()` for every single `code_type`,
# zbarlight doesn't yet provide a more efficient way to do this, see:
# https://github.com/Polyconseil/zbarlight/issues/23
symbols = []
for code_type in self.code_types:
codes = zbarlight.scan_codes(code_type, pil_image) or []
for code in codes:
symbol = ZBarCam.Symbol(type=code_type, data=code)
symbols.append(symbol)
self.symbols = symbols
return zbarlight.scan_codes(code_types, pil_image) or []

@property
def xcamera(self):
Expand All @@ -121,7 +111,7 @@ def is_android(self):
Label:
size_hint: None, None
size: self.texture_size[0], 50
text: ', '.join([str(symbol.data) for symbol in zbarcam.symbols])
text: ', '.join([str(code) for code in zbarcam.codes])
"""


Expand Down

0 comments on commit f146e68

Please sign in to comment.