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/20190222'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Feb 22, 2019
2 parents 9a92c35 + 1a43601 commit 16d960a
Show file tree
Hide file tree
Showing 21 changed files with 461 additions and 51 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
venv/
.git/
.buildozer/
.pytest_cache/
.tox/
opencv*
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sudo: required

language: generic

services:
- docker

env:
global:
- DISPLAY=:99.0
matrix:
- TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make test'
- TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make uitest'
- TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug'

before_install:
- sudo apt update -qq > /dev/null
- sudo apt install --yes --no-install-recommends xvfb

install:
- docker build --tag=$TAG --file=$DOCKERFILE .

before_script:
- sh -e /etc/init.d/xvfb start

script:
- travis_wait docker run -e DISPLAY -e CI -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [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

## [20171220]

- Full screen camera
Expand Down
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
VENV_NAME=venv
PIP=$(VENV_NAME)/bin/pip
TOX=`which tox`
GARDEN=$(VENV_NAME)/bin/garden
PYTHON=$(VENV_NAME)/bin/python
SYSTEM_DEPENDENCIES=virtualenv build-essential libpython2.7-dev libsdl2-dev libzbar-dev \
cmake python-numpy tox wget curl
OS=$(shell lsb_release -si)
OPENCV_VERSION=2.4.13.6
OPENCV_BASENAME=opencv-$(OPENCV_VERSION)
OPENCV_BUILD=$(OPENCV_BASENAME)/build/lib/cv2.so
OPENCV_DEPLOY=$(VENV_NAME)/lib/python2.7/site-packages/cv2.so
NPROC=`grep -c '^processor' /proc/cpuinfo`


all: system_dependencies opencv virtualenv

virtualenv:
test -d venv || virtualenv -p python2 venv
. venv/bin/activate
$(PIP) install Cython==0.26.1
$(PIP) install -r requirements/requirements.txt
$(GARDEN) install xcamera

system_dependencies:
ifeq ($(OS), Ubuntu)
sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES)
endif

$(OPENCV_BUILD):
curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \
--progress-bar --output $(OPENCV_BASENAME).tar.gz
tar -xf $(OPENCV_BASENAME).tar.gz
cmake \
-D BUILD_DOCS=OFF -D BUILD_PACKAGE=OFF -D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF -D BUILD_opencv_apps=OFF \
-D BUILD_opencv_nonfree=OFF -D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_superres=OFF -D BUILD_opencv_ts=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF -D WITH_1394=OFF -D WITH_CUDA=OFF \
-D WITH_CUFFT=OFF -D WITH_GIGEAPI=OFF -D WITH_JASPER=OFF \
-D WITH_OPENEXR=OFF -D WITH_PVAPI=OFF -D WITH_GTK=OFF \
-D BUILD_opencv_python=ON -B$(OPENCV_BASENAME)/build -H$(OPENCV_BASENAME)
cmake --build $(OPENCV_BASENAME)/build -- -j$(NPROC)

opencv_build: $(OPENCV_BUILD)

$(OPENCV_DEPLOY): opencv_build virtualenv
cp $(OPENCV_BUILD) $(OPENCV_DEPLOY)

opencv: $(OPENCV_DEPLOY)

clean:
rm -rf $(VENV_NAME) .tox/ $(OPENCV_BASENAME)

test:
$(TOX)

uitest: virtualenv
$(PIP) install -r requirements/test_requirements.txt
$(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/
18 changes: 6 additions & 12 deletions OpenCV.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
In order to be able to use the camera on Linux, you need to compile OpenCV.
Simply installing `opencv-python` from pypi is not enough.
Currently only OpenCV2 works with Kivy on Linux (see https://github.com/kivy/kivy/issues/5404).
Download and extract the OpenCV2 archive:
```
wget https://github.com/opencv/opencv/archive/2.4.13.3.tar.gz -O opencv-2.4.13.3.tar.gz
tar -xvzf opencv-2.4.13.3.tar.gz
```
Prepare and build:

Use the [Makefile](Makefile) provided to compile and install OpenCV library.
```
cd opencv-2.4.13.3/
mkdir build && cd build/
cmake ..
make -j4
make system_dependencies
make opencv_build
```
Copy your compiled `cv2.so` to your virtualenv:
Then copy your compiled `cv2.so` to your virtualenv:
```
cp lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
cp opencv-*/build/lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
```
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# garden.zbarcam

[![Build Status](https://secure.travis-ci.org/kivy-garden/garden.zbarcam.png?branch=develop)](http://travis-ci.org/kivy-garden/garden.zbarcam)

Real time Barcode and QR Code scanner using the camera.
It's built on top of [Kivy](https://github.com/kivy/kivy) and [ZBar](https://github.com/ZBar/ZBar).
It's built on top of [Kivy](https://github.com/kivy/kivy) and [ZbarLight](https://github.com/Polyconseil/zbarlight).

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

## How to use
Simply import and instanciate `ZBarCam` in your kvlang file and access its `symbols` property.
```
#:import ZBarCam zbarcam
```yaml
#:import ZBarCam kivy.garden.zbarcam
BoxLayout:
orientation: 'vertical'
ZBarCam:
id: zbarcam
# optional, by default checks all types
code_types: 'qrcode', 'ean13'
Label:
size_y: 20
size_hint_y: None
Expand All @@ -21,24 +25,40 @@ BoxLayout:
## Install
Install system requirements (Ubuntu 16.04):
```
```sh
sudo apt install libzbar-dev
```

Install garden requirements:
```
```sh
garden install xcamera
```

Install zbarcam:
```
```sh
garden install zbarcam
```

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

## Contribute
To play with the project, install system dependencies and Python requirements using the [Makefile](Makefile).
```sh
make
```
Then verify everything is OK by running tests.
```sh
make test
```

## Troubleshooting

### Install `Unable to import package 'kivy.garden.xcamera.XCamera'`
Missing the `xcamera` dependency, install it with:
```sh
garden install xcamera
```

### Android `ValueError: Empty module name`
More likely an import issue in your `.kv` file.
Try to `from zbarcam import ZBarCam` in your `main.py` to see the exact error.
Expand Down
17 changes: 14 additions & 3 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ source.include_exts = py,png,jpg,kv,atlas
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
version = 0.1
# version = 0.1

# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py
version.filename = %(source.dir)s/zbarcam/version.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy, pil, libiconv, libzbar, zbar
requirements = kivy, pil, libiconv, libzbar, zbarlight==1.2
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
Expand Down Expand Up @@ -118,6 +121,12 @@ android.permissions = CAMERA
# when an update is due and you just want to test/build your package
# android.skip_update = False
# (bool) If True, then automatically accept SDK license
# agreements. This is intended for automation only. If set to False,
# the default, you will be shown the license when first running
# buildozer.
android.accept_sdk_license = True
# (str) Android entry point, default is ok for Kivy-based app
#android.entrypoint = org.renpy.android.PythonActivity
Expand Down Expand Up @@ -150,6 +159,7 @@ android.permissions = CAMERA
# (str) python-for-android branch to use, defaults to master
#p4a.branch = stable
p4a.branch = master
# (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled
Expand Down Expand Up @@ -196,6 +206,7 @@ android.arch = armeabi-v7a
# (str) The directory in which python-for-android should look for your own build recipes (if any)
#p4a.local_recipes =
p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
# (str) Filename to the hook for p4a
#p4a.hook =
Expand All @@ -222,7 +233,7 @@ android.arch = armeabi-v7a
[buildozer]
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2
log_level = 1
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1
Expand Down
56 changes: 56 additions & 0 deletions dockerfiles/Dockerfile-android
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Docker image for building Android APKs via buildozer
# Build with:
# docker build --tag=zbarcam-android --file=dockerfiles/Dockerfile-android .
# Run with:
# docker run zbarcam-android /bin/sh -c 'buildozer android debug'
# Or using the entry point shortcut:
# docker run zbarcam-android 'buildozer android debug'
# Or for interactive shell:
# docker run -it --rm zbarcam-android
FROM ubuntu:18.04

ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
ENV DOCKERFILES_VERSION="master" \
DOCKERFILES_URL="https://raw.githubusercontent.com/AndreMiras/dockerfiles"
ENV MAKEFILES_URL="${DOCKERFILES_URL}/${DOCKERFILES_VERSION}/buildozer_android_new"


# configure locale
RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \
locales && \
locale-gen en_US.UTF-8
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="en_US.UTF-8"

# install system dependencies (required to setup all the tools)
RUN apt install -qq --yes --no-install-recommends \
cmake make curl ca-certificates xz-utils unzip openjdk-8-jdk sudo \
python-pip python-setuptools zip

# install build dependencies (required to successfully build the project)
# TODO: should this go to a Makefile instead so it can be shared/reused?
RUN apt install -qq --yes --no-install-recommends \
python3.6 libpython3.6-dev python3-setuptools \
file autoconf automake libtool gettext pkg-config

# prepare non root env
RUN useradd --create-home --shell /bin/bash ${USER}
# with sudo access and no password
RUN usermod -append --groups sudo ${USER}
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER ${USER}
WORKDIR ${WORK_DIR}

# install buildozer and dependencies
RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk
RUN make -f buildozer.mk
# enforces buildozer master (afebba5) until next release
RUN pip install --upgrade https://github.com/kivy/buildozer/archive/afebba5.zip

COPY . ${WORK_DIR}
ENTRYPOINT ["./dockerfiles/start.sh"]
48 changes: 48 additions & 0 deletions dockerfiles/Dockerfile-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Docker image for installing dependencies on Linux and running tests.
# Build with:
# docker build --tag=zbarcam-linux --file=dockerfiles/Dockerfile-linux .
# Run with:
# docker run zbarcam-linux /bin/sh -c 'make test'
# Or using the entry point shortcut:
# docker run zbarcam-linux 'make test'
# For running UI:
# xhost +"local:docker@"
# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix zbarcam-linux 'make uitest'
# Or for interactive shell:
# docker run -it --rm zbarcam-linux
FROM ubuntu:18.04

ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}"

# configure locale
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
locales && \
locale-gen en_US.UTF-8
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="en_US.UTF-8"

# install system dependencies
RUN apt install --yes --no-install-recommends \
python python-dev virtualenv make lsb-release pkg-config build-essential \
sudo tox

# install kivy system dependencies
# https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2
RUN apt install --yes --no-install-recommends \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev

# prepare non root env
RUN useradd --create-home --shell /bin/bash ${USER}
# with sudo access and no password
RUN usermod -append --groups sudo ${USER}
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER ${USER}
WORKDIR ${WORK_DIR}
COPY . ${WORK_DIR}

RUN make
ENTRYPOINT ["./dockerfiles/start.sh"]
10 changes: 10 additions & 0 deletions dockerfiles/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# if a some command has been passed to container, executes it and exit,
# otherwise runs bash
if [[ $@ ]]; then
eval $@
else
/bin/bash
fi
Loading

0 comments on commit 16d960a

Please sign in to comment.