Skip to content

Commit

Permalink
Merge branch 'release/20190303'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Mar 3, 2019
2 parents f146e68 + e7bf68e commit ddafb79
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 202 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
venv/
.git/
.buildozer/
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_install:
- sudo apt install --yes --no-install-recommends xvfb

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

before_script:
- sh -e /etc/init.d/xvfb start
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## [20190303]

- Add Python3.6 support, refs #5
- Fully migrated Android from PIL to Pillow, refs #13
- Handle Android runtime permissions, refs #30
- Fixe codes not detected on Android, refs #32
- Migrate from zbarlight to pyzbar, refs #32
- Migrate to Python3.6 and opencv 4, refs #33

## [20190223]

- Fix zbarlight dependency in setup.py, refs #28
Expand Down
93 changes: 71 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,98 @@ 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
SYSTEM_DEPENDENCIES= \
build-essential \
cmake \
curl \
libpython$(PYTHON_VERSION)-dev \
libsdl2-dev \
libzbar-dev \
tox \
virtualenv \
wget
OS=$(shell lsb_release -si)
OPENCV_VERSION=2.4.13.6
PYTHON_MAJOR_VERSION=3
PYTHON_MINOR_VERSION=6
PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION)
PYTHON_WITH_VERSION=python$(PYTHON_VERSION)
# python3 has a "m" suffix for both include path and library
PYTHON_M=$(PYTHON_WITH_VERSION)
SITE_PACKAGES_DIR=$(VENV_NAME)/lib/$(PYTHON_WITH_VERSION)/site-packages
OPENCV_VERSION=4.0.1
OPENCV_ARCHIVE=$(OPENCV_BASENAME).tar.gz
OPENCV_BASENAME=opencv-$(OPENCV_VERSION)
OPENCV_BUILD=$(OPENCV_BASENAME)/build/lib/cv2.so
OPENCV_DEPLOY=$(VENV_NAME)/lib/python2.7/site-packages/cv2.so
OPENCV_BUILD_LIB_DIR=$(OPENCV_BASENAME)/build/lib
OPENCV_BUILD=$(OPENCV_BUILD_LIB_DIR)/python$(PYTHON_MAJOR_VERSION)/cv2*.so
OPENCV_DEPLOY=$(SITE_PACKAGES_DIR)/cv2*.so
NPROC=`grep -c '^processor' /proc/cpuinfo`
ifeq ($(PYTHON_MAJOR_VERSION), 3)
PYTHON_M := $(PYTHON_M)m
endif


all: system_dependencies opencv virtualenv
all: system_dependencies virtualenv opencv

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

virtualenv: venv

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

$(OPENCV_BUILD):
$(OPENCV_ARCHIVE):
curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \
--progress-bar --output $(OPENCV_BASENAME).tar.gz
--progress-bar --output $(OPENCV_ARCHIVE)

# The build also relies on virtualenv, because we make references to it.
# Plus numpy is required to build OpenCV Python module.
$(OPENCV_BUILD): $(OPENCV_ARCHIVE) virtualenv
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)
-D CMAKE_SHARED_LINKER_FLAGS=-l$(PYTHON_M) \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_STATIC_LIBS=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_OPENCV_APPS=OFF \
-D BUILD_OPENCV_JAVA=OFF \
-D BUILD_OPENCV_JAVA_BINDINGS_GENERATOR=OFF \
-D BUILD_OPENCV_NONFREE=OFF \
-D BUILD_OPENCV_PYTHON2=OFF \
-D BUILD_OPENCV_PYTHON3=ON \
-D BUILD_OPENCV_STITCHING=OFF \
-D BUILD_OPENCV_SUPERRES=OFF \
-D BUILD_OPENCV_TS=OFF \
-D BUILD_PACKAGE=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D OPENCV_SKIP_PYTHON_LOADER=ON \
-D OPENCV_PYTHON$(PYTHON_MAJOR_VERSION)_INSTALL_PATH=$(SITE_PACKAGES_DIR) \
-D PYTHON$(PYTHON_MAJOR_VERSION)_PACKAGES_PATH=$(SITE_PACKAGES_DIR) \
-D PYTHON$(PYTHON_MAJOR_VERSION)_EXECUTABLE=$(PYTHON) \
-D PYTHON$(PYTHON_MAJOR_VERSION)_INCLUDE_PATH=/usr/include/$(PYTHON_M)/ \
-D PYTHON$(PYTHON_MAJOR_VERSION)_LIBRARIES=/usr/lib/x86_64-linux-gnu/lib$(PYTHON_M).so \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python$(PYTHON_MAJOR_VERSION) \
-D WITH_1394=OFF \
-D WITH_CUDA=OFF \
-D WITH_CUFFT=OFF \
-D WITH_GIGEAPI=OFF \
-D WITH_GTK=OFF \
-D WITH_JASPER=OFF \
-D WITH_OPENEXR=OFF \
-D WITH_PVAPI=OFF \
-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_DEPLOY): $(OPENCV_BUILD) virtualenv
cp $(OPENCV_BUILD) $(SITE_PACKAGES_DIR)

opencv: $(OPENCV_DEPLOY)

Expand Down
8 changes: 2 additions & 6 deletions OpenCV.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
## Linux Camera support
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).

Use the [Makefile](Makefile) provided to compile and install OpenCV library.
```
make system_dependencies
make opencv_build
```
Then copy your compiled `cv2.so` to your virtualenv:
```
cp opencv-*/build/lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
make opencv
```
It would build OpenCV and deploy it to your virtualenv.
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@
[![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 [ZbarLight](https://github.com/Polyconseil/zbarlight).
It's built on top of [Kivy](https://github.com/kivy/kivy) and [pyzbar](https://github.com/NaturalHistoryMuseum/pyzbar).

<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.
```yaml
#:import ZBarCam kivy.garden.zbarcam
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
BoxLayout:
orientation: 'vertical'
ZBarCam:
id: zbarcam
# optional, by default checks all types
code_types: 'qrcode', 'ean13'
code_types: ZBarSymbol.QRCODE, ZBarSymbol.EAN13
Label:
size_y: 20
size_hint_y: None
text: ", ".join([str(code) for code in zbarcam.codes])
size_hint: None, None
size: self.texture_size[0], 50
text: ', '.join([str(symbol.data) for symbol in zbarcam.symbols])
```
## Install
Install system requirements (Ubuntu 16.04):
### Ubuntu
Install system requirements (Ubuntu 18.04):
```sh
sudo apt install libzbar-dev
```
Expand All @@ -35,12 +38,20 @@ garden install xcamera
```

Install zbarcam:
Via `garden`:
```sh
garden install --upgrade zbarcam
```
Via `pip`:
```sh
garden install zbarcam
pip install --upgrade https://github.com/kivy-garden/garden.zbarcam/archive/develop.zip
```

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

### Android
Build for Android via buildozer, see [buildozer.spec](buildozer.spec).

## Contribute
To play with the project, install system dependencies and Python requirements using the [Makefile](Makefile).
```sh
Expand All @@ -49,6 +60,7 @@ make
Then verify everything is OK by running tests.
```sh
make test
make uitest
```

## Troubleshooting
Expand All @@ -62,7 +74,7 @@ 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.
It's common to forget `pil` in `buildozer.spec` `requirements` section.
It's common to forget `Pillow` in `buildozer.spec` `requirements` section.

## Credits
I borrowed a lot of code from [tito/android-zbar-qrcode](https://github.com/tito/android-zbar-qrcode).
33 changes: 19 additions & 14 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source.include_exts = py,png,jpg,kv,atlas
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin
source.exclude_dirs = tests, bin, venv, opencv-*

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
Expand All @@ -31,14 +31,19 @@ source.include_exts = py,png,jpg,kv,atlas
# 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, zbarlight>=2.1
requirements =
android,
kivy==5fc5385,
libiconv,
libzbar,
Pillow==5.2.0,
python3,
pyzbar==0.1.8
# (str) Custom source folders for requirements
Expand Down Expand Up @@ -89,20 +94,22 @@ fullscreen = 0
#android.presplash_color = #FFFFFF
# (list) Permissions
#android.permissions = INTERNET
android.permissions = CAMERA
# (int) Android API to use
#android.api = 19
# (int) Target Android API, should be as high as possible.
android.api = 27
# (int) Minimum API required
#android.minapi = 9
# (int) Minimum API your APK will support.
android.minapi = 21
# (int) Android SDK version to use
#android.sdk = 20
android.sdk = 20
# (str) Android NDK version to use
#android.ndk = 9c
android.ndk = 17c
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
android.ndk_api = 21
# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True
Expand Down Expand Up @@ -158,7 +165,6 @@ android.accept_sdk_license = True
#android.gradle_dependencies =
# (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
Expand Down Expand Up @@ -206,7 +212,6 @@ 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 @@ -233,7 +238,7 @@ p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
[buildozer]
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 1
log_level = 2
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1
Expand Down
39 changes: 28 additions & 11 deletions dockerfiles/Dockerfile-android
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# docker run -it --rm zbarcam-android
FROM ubuntu:18.04

ARG CI=false
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}" \
Expand All @@ -26,16 +27,30 @@ 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)
# install system dependencies
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
autoconf \
automake \
cmake \
make \
ca-certificates \
curl \
gettext \
libffi-dev \
libltdl-dev \
libpython3.6-dev \
libtool \
file \
openjdk-8-jdk \
pkg-config \
python3.6 \
python3-setuptools \
python-pip \
python-setuptools \
sudo \
unzip \
xz-utils \
zip

# prepare non root env
RUN useradd --create-home --shell /bin/bash ${USER}
Expand All @@ -49,8 +64,10 @@ 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
# enforces buildozer master (cf880a3) until next release
RUN pip install --upgrade https://github.com/kivy/buildozer/archive/cf880a3.zip

COPY . ${WORK_DIR}
# limits the amount of logs for Travis
RUN if [ "${CI}" = "true" ]; then sed 's/log_level = [0-9]/log_level = 1/' -i buildozer.spec; fi
ENTRYPOINT ["./dockerfiles/start.sh"]
Loading

0 comments on commit ddafb79

Please sign in to comment.