Skip to content

Commit 16d960a

Browse files
committed
Merge branch 'release/20190222'
2 parents 9a92c35 + 1a43601 commit 16d960a

File tree

21 files changed

+461
-51
lines changed

21 files changed

+461
-51
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
venv/
2+
.git/
3+
.buildozer/
4+
.pytest_cache/
5+
.tox/
6+
opencv*

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
sudo: required
2+
3+
language: generic
4+
5+
services:
6+
- docker
7+
8+
env:
9+
global:
10+
- DISPLAY=:99.0
11+
matrix:
12+
- TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make test'
13+
- TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make uitest'
14+
- TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug'
15+
16+
before_install:
17+
- sudo apt update -qq > /dev/null
18+
- sudo apt install --yes --no-install-recommends xvfb
19+
20+
install:
21+
- docker build --tag=$TAG --file=$DOCKERFILE .
22+
23+
before_script:
24+
- sh -e /etc/init.d/xvfb start
25+
26+
script:
27+
- travis_wait docker run -e DISPLAY -e CI -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## [20190222]
4+
5+
- Provide Makefile, refs #15
6+
- Setup continuous integration testing, refs #6, #14
7+
- Speedup OpenCV compilation time, refs #16
8+
- Migrated to zbarlight, refs #5, #13
9+
- Introduced UI tests, refs #4
10+
- Using non-root Docker container, refs #27
11+
- Run UI tests from Travis, refs #26
12+
313
## [20171220]
414

515
- Full screen camera

Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
VENV_NAME=venv
2+
PIP=$(VENV_NAME)/bin/pip
3+
TOX=`which tox`
4+
GARDEN=$(VENV_NAME)/bin/garden
5+
PYTHON=$(VENV_NAME)/bin/python
6+
SYSTEM_DEPENDENCIES=virtualenv build-essential libpython2.7-dev libsdl2-dev libzbar-dev \
7+
cmake python-numpy tox wget curl
8+
OS=$(shell lsb_release -si)
9+
OPENCV_VERSION=2.4.13.6
10+
OPENCV_BASENAME=opencv-$(OPENCV_VERSION)
11+
OPENCV_BUILD=$(OPENCV_BASENAME)/build/lib/cv2.so
12+
OPENCV_DEPLOY=$(VENV_NAME)/lib/python2.7/site-packages/cv2.so
13+
NPROC=`grep -c '^processor' /proc/cpuinfo`
14+
15+
16+
all: system_dependencies opencv virtualenv
17+
18+
virtualenv:
19+
test -d venv || virtualenv -p python2 venv
20+
. venv/bin/activate
21+
$(PIP) install Cython==0.26.1
22+
$(PIP) install -r requirements/requirements.txt
23+
$(GARDEN) install xcamera
24+
25+
system_dependencies:
26+
ifeq ($(OS), Ubuntu)
27+
sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES)
28+
endif
29+
30+
$(OPENCV_BUILD):
31+
curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \
32+
--progress-bar --output $(OPENCV_BASENAME).tar.gz
33+
tar -xf $(OPENCV_BASENAME).tar.gz
34+
cmake \
35+
-D BUILD_DOCS=OFF -D BUILD_PACKAGE=OFF -D BUILD_PERF_TESTS=OFF \
36+
-D BUILD_TESTS=OFF -D BUILD_opencv_apps=OFF \
37+
-D BUILD_opencv_nonfree=OFF -D BUILD_opencv_stitching=OFF \
38+
-D BUILD_opencv_superres=OFF -D BUILD_opencv_ts=OFF \
39+
-D BUILD_WITH_DEBUG_INFO=OFF -D WITH_1394=OFF -D WITH_CUDA=OFF \
40+
-D WITH_CUFFT=OFF -D WITH_GIGEAPI=OFF -D WITH_JASPER=OFF \
41+
-D WITH_OPENEXR=OFF -D WITH_PVAPI=OFF -D WITH_GTK=OFF \
42+
-D BUILD_opencv_python=ON -B$(OPENCV_BASENAME)/build -H$(OPENCV_BASENAME)
43+
cmake --build $(OPENCV_BASENAME)/build -- -j$(NPROC)
44+
45+
opencv_build: $(OPENCV_BUILD)
46+
47+
$(OPENCV_DEPLOY): opencv_build virtualenv
48+
cp $(OPENCV_BUILD) $(OPENCV_DEPLOY)
49+
50+
opencv: $(OPENCV_DEPLOY)
51+
52+
clean:
53+
rm -rf $(VENV_NAME) .tox/ $(OPENCV_BASENAME)
54+
55+
test:
56+
$(TOX)
57+
58+
uitest: virtualenv
59+
$(PIP) install -r requirements/test_requirements.txt
60+
$(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/

OpenCV.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
In order to be able to use the camera on Linux, you need to compile OpenCV.
55
Simply installing `opencv-python` from pypi is not enough.
66
Currently only OpenCV2 works with Kivy on Linux (see https://github.com/kivy/kivy/issues/5404).
7-
Download and extract the OpenCV2 archive:
8-
```
9-
wget https://github.com/opencv/opencv/archive/2.4.13.3.tar.gz -O opencv-2.4.13.3.tar.gz
10-
tar -xvzf opencv-2.4.13.3.tar.gz
11-
```
12-
Prepare and build:
7+
8+
Use the [Makefile](Makefile) provided to compile and install OpenCV library.
139
```
14-
cd opencv-2.4.13.3/
15-
mkdir build && cd build/
16-
cmake ..
17-
make -j4
10+
make system_dependencies
11+
make opencv_build
1812
```
19-
Copy your compiled `cv2.so` to your virtualenv:
13+
Then copy your compiled `cv2.so` to your virtualenv:
2014
```
21-
cp lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
15+
cp opencv-*/build/lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
2216
```

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# garden.zbarcam
22

3+
[![Build Status](https://secure.travis-ci.org/kivy-garden/garden.zbarcam.png?branch=develop)](http://travis-ci.org/kivy-garden/garden.zbarcam)
4+
35
Real time Barcode and QR Code scanner using the camera.
4-
It's built on top of [Kivy](https://github.com/kivy/kivy) and [ZBar](https://github.com/ZBar/ZBar).
6+
It's built on top of [Kivy](https://github.com/kivy/kivy) and [ZbarLight](https://github.com/Polyconseil/zbarlight).
57

68
<img src="https://raw.githubusercontent.com/AndreMiras/garden.zbarcam/develop/screenshot.gif" align="right" width="256" alt="screenshot" />
79

810
## How to use
911
Simply import and instanciate `ZBarCam` in your kvlang file and access its `symbols` property.
10-
```
11-
#:import ZBarCam zbarcam
12+
```yaml
13+
#:import ZBarCam kivy.garden.zbarcam
1214
BoxLayout:
1315
orientation: 'vertical'
1416
ZBarCam:
1517
id: zbarcam
18+
# optional, by default checks all types
19+
code_types: 'qrcode', 'ean13'
1620
Label:
1721
size_y: 20
1822
size_hint_y: None
@@ -21,24 +25,40 @@ BoxLayout:
2125
2226
## Install
2327
Install system requirements (Ubuntu 16.04):
24-
```
28+
```sh
2529
sudo apt install libzbar-dev
2630
```
2731

2832
Install garden requirements:
29-
```
33+
```sh
3034
garden install xcamera
3135
```
3236

3337
Install zbarcam:
34-
```
38+
```sh
3539
garden install zbarcam
3640
```
3741

3842
You may also need to compile/install OpenCV manually, see [OpenCV.md](OpenCV.md).
3943

44+
## Contribute
45+
To play with the project, install system dependencies and Python requirements using the [Makefile](Makefile).
46+
```sh
47+
make
48+
```
49+
Then verify everything is OK by running tests.
50+
```sh
51+
make test
52+
```
53+
4054
## Troubleshooting
4155

56+
### Install `Unable to import package 'kivy.garden.xcamera.XCamera'`
57+
Missing the `xcamera` dependency, install it with:
58+
```sh
59+
garden install xcamera
60+
```
61+
4262
### Android `ValueError: Empty module name`
4363
More likely an import issue in your `.kv` file.
4464
Try to `from zbarcam import ZBarCam` in your `main.py` to see the exact error.

buildozer.spec

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ source.include_exts = py,png,jpg,kv,atlas
2828
#source.exclude_patterns = license,images/*/*.jpg
2929

3030
# (str) Application versioning (method 1)
31-
version = 0.1
31+
# version = 0.1
3232

3333
# (str) Application versioning (method 2)
3434
# version.regex = __version__ = ['"](.*)['"]
35+
version.regex = __version__ = ['"](.*)['"]
3536
# version.filename = %(source.dir)s/main.py
37+
version.filename = %(source.dir)s/zbarcam/version.py
3638
3739
# (list) Application requirements
3840
# comma seperated e.g. requirements = sqlite3,kivy
39-
requirements = kivy, pil, libiconv, libzbar, zbar
41+
requirements = kivy, pil, libiconv, libzbar, zbarlight==1.2
42+
4043
4144
# (str) Custom source folders for requirements
4245
# Sets custom source for any requirements with recipes
@@ -118,6 +121,12 @@ android.permissions = CAMERA
118121
# when an update is due and you just want to test/build your package
119122
# android.skip_update = False
120123
124+
# (bool) If True, then automatically accept SDK license
125+
# agreements. This is intended for automation only. If set to False,
126+
# the default, you will be shown the license when first running
127+
# buildozer.
128+
android.accept_sdk_license = True
129+
121130
# (str) Android entry point, default is ok for Kivy-based app
122131
#android.entrypoint = org.renpy.android.PythonActivity
123132
@@ -150,6 +159,7 @@ android.permissions = CAMERA
150159
151160
# (str) python-for-android branch to use, defaults to master
152161
#p4a.branch = stable
162+
p4a.branch = master
153163
154164
# (str) OUYA Console category. Should be one of GAME or APP
155165
# If you leave this blank, OUYA support will not be enabled
@@ -196,6 +206,7 @@ android.arch = armeabi-v7a
196206
197207
# (str) The directory in which python-for-android should look for your own build recipes (if any)
198208
#p4a.local_recipes =
209+
p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
199210
200211
# (str) Filename to the hook for p4a
201212
#p4a.hook =
@@ -222,7 +233,7 @@ android.arch = armeabi-v7a
222233
[buildozer]
223234
224235
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
225-
log_level = 2
236+
log_level = 1
226237
227238
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
228239
warn_on_root = 1

dockerfiles/Dockerfile-android

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Docker image for building Android APKs via buildozer
2+
# Build with:
3+
# docker build --tag=zbarcam-android --file=dockerfiles/Dockerfile-android .
4+
# Run with:
5+
# docker run zbarcam-android /bin/sh -c 'buildozer android debug'
6+
# Or using the entry point shortcut:
7+
# docker run zbarcam-android 'buildozer android debug'
8+
# Or for interactive shell:
9+
# docker run -it --rm zbarcam-android
10+
FROM ubuntu:18.04
11+
12+
ENV USER="user"
13+
ENV HOME_DIR="/home/${USER}"
14+
ENV WORK_DIR="${HOME_DIR}" \
15+
PATH="${HOME_DIR}/.local/bin:${PATH}"
16+
ENV DOCKERFILES_VERSION="master" \
17+
DOCKERFILES_URL="https://raw.githubusercontent.com/AndreMiras/dockerfiles"
18+
ENV MAKEFILES_URL="${DOCKERFILES_URL}/${DOCKERFILES_VERSION}/buildozer_android_new"
19+
20+
21+
# configure locale
22+
RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \
23+
locales && \
24+
locale-gen en_US.UTF-8
25+
ENV LANG="en_US.UTF-8" \
26+
LANGUAGE="en_US.UTF-8" \
27+
LC_ALL="en_US.UTF-8"
28+
29+
# install system dependencies (required to setup all the tools)
30+
RUN apt install -qq --yes --no-install-recommends \
31+
cmake make curl ca-certificates xz-utils unzip openjdk-8-jdk sudo \
32+
python-pip python-setuptools zip
33+
34+
# install build dependencies (required to successfully build the project)
35+
# TODO: should this go to a Makefile instead so it can be shared/reused?
36+
RUN apt install -qq --yes --no-install-recommends \
37+
python3.6 libpython3.6-dev python3-setuptools \
38+
file autoconf automake libtool gettext pkg-config
39+
40+
# prepare non root env
41+
RUN useradd --create-home --shell /bin/bash ${USER}
42+
# with sudo access and no password
43+
RUN usermod -append --groups sudo ${USER}
44+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
45+
46+
USER ${USER}
47+
WORKDIR ${WORK_DIR}
48+
49+
# install buildozer and dependencies
50+
RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk
51+
RUN make -f buildozer.mk
52+
# enforces buildozer master (afebba5) until next release
53+
RUN pip install --upgrade https://github.com/kivy/buildozer/archive/afebba5.zip
54+
55+
COPY . ${WORK_DIR}
56+
ENTRYPOINT ["./dockerfiles/start.sh"]

dockerfiles/Dockerfile-linux

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Docker image for installing dependencies on Linux and running tests.
2+
# Build with:
3+
# docker build --tag=zbarcam-linux --file=dockerfiles/Dockerfile-linux .
4+
# Run with:
5+
# docker run zbarcam-linux /bin/sh -c 'make test'
6+
# Or using the entry point shortcut:
7+
# docker run zbarcam-linux 'make test'
8+
# For running UI:
9+
# xhost +"local:docker@"
10+
# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix zbarcam-linux 'make uitest'
11+
# Or for interactive shell:
12+
# docker run -it --rm zbarcam-linux
13+
FROM ubuntu:18.04
14+
15+
ENV USER="user"
16+
ENV HOME_DIR="/home/${USER}"
17+
ENV WORK_DIR="${HOME_DIR}"
18+
19+
# configure locale
20+
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
21+
locales && \
22+
locale-gen en_US.UTF-8
23+
ENV LANG="en_US.UTF-8" \
24+
LANGUAGE="en_US.UTF-8" \
25+
LC_ALL="en_US.UTF-8"
26+
27+
# install system dependencies
28+
RUN apt install --yes --no-install-recommends \
29+
python python-dev virtualenv make lsb-release pkg-config build-essential \
30+
sudo tox
31+
32+
# install kivy system dependencies
33+
# https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2
34+
RUN apt install --yes --no-install-recommends \
35+
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
36+
37+
# prepare non root env
38+
RUN useradd --create-home --shell /bin/bash ${USER}
39+
# with sudo access and no password
40+
RUN usermod -append --groups sudo ${USER}
41+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
42+
43+
USER ${USER}
44+
WORKDIR ${WORK_DIR}
45+
COPY . ${WORK_DIR}
46+
47+
RUN make
48+
ENTRYPOINT ["./dockerfiles/start.sh"]

dockerfiles/start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# if a some command has been passed to container, executes it and exit,
5+
# otherwise runs bash
6+
if [[ $@ ]]; then
7+
eval $@
8+
else
9+
/bin/bash
10+
fi

0 commit comments

Comments
 (0)