Skip to content

Commit ddafb79

Browse files
committed
Merge branch 'release/20190303'
2 parents f146e68 + e7bf68e commit ddafb79

File tree

18 files changed

+230
-202
lines changed

18 files changed

+230
-202
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
bin/
12
venv/
23
.git/
34
.buildozer/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ before_install:
1818
- sudo apt install --yes --no-install-recommends xvfb
1919

2020
install:
21-
- docker build --tag=$TAG --file=$DOCKERFILE .
21+
- docker build --tag=$TAG --file=$DOCKERFILE --build-arg CI .
2222

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

CHANGELOG.md

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

3+
## [20190303]
4+
5+
- Add Python3.6 support, refs #5
6+
- Fully migrated Android from PIL to Pillow, refs #13
7+
- Handle Android runtime permissions, refs #30
8+
- Fixe codes not detected on Android, refs #32
9+
- Migrate from zbarlight to pyzbar, refs #32
10+
- Migrate to Python3.6 and opencv 4, refs #33
11+
312
## [20190223]
413

514
- Fix zbarlight dependency in setup.py, refs #28

Makefile

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,98 @@ PIP=$(VENV_NAME)/bin/pip
33
TOX=`which tox`
44
GARDEN=$(VENV_NAME)/bin/garden
55
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
6+
SYSTEM_DEPENDENCIES= \
7+
build-essential \
8+
cmake \
9+
curl \
10+
libpython$(PYTHON_VERSION)-dev \
11+
libsdl2-dev \
12+
libzbar-dev \
13+
tox \
14+
virtualenv \
15+
wget
816
OS=$(shell lsb_release -si)
9-
OPENCV_VERSION=2.4.13.6
17+
PYTHON_MAJOR_VERSION=3
18+
PYTHON_MINOR_VERSION=6
19+
PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION)
20+
PYTHON_WITH_VERSION=python$(PYTHON_VERSION)
21+
# python3 has a "m" suffix for both include path and library
22+
PYTHON_M=$(PYTHON_WITH_VERSION)
23+
SITE_PACKAGES_DIR=$(VENV_NAME)/lib/$(PYTHON_WITH_VERSION)/site-packages
24+
OPENCV_VERSION=4.0.1
25+
OPENCV_ARCHIVE=$(OPENCV_BASENAME).tar.gz
1026
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
27+
OPENCV_BUILD_LIB_DIR=$(OPENCV_BASENAME)/build/lib
28+
OPENCV_BUILD=$(OPENCV_BUILD_LIB_DIR)/python$(PYTHON_MAJOR_VERSION)/cv2*.so
29+
OPENCV_DEPLOY=$(SITE_PACKAGES_DIR)/cv2*.so
1330
NPROC=`grep -c '^processor' /proc/cpuinfo`
31+
ifeq ($(PYTHON_MAJOR_VERSION), 3)
32+
PYTHON_M := $(PYTHON_M)m
33+
endif
1434

1535

16-
all: system_dependencies opencv virtualenv
36+
all: system_dependencies virtualenv opencv
1737

18-
virtualenv:
19-
test -d venv || virtualenv -p python2 venv
38+
venv:
39+
test -d venv || virtualenv -p python$(PYTHON_MAJOR_VERSION) venv
2040
. venv/bin/activate
2141
$(PIP) install Cython==0.26.1
2242
$(PIP) install -r requirements/requirements.txt
2343
$(GARDEN) install xcamera
2444

45+
virtualenv: venv
46+
2547
system_dependencies:
2648
ifeq ($(OS), Ubuntu)
2749
sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES)
2850
endif
2951

30-
$(OPENCV_BUILD):
52+
$(OPENCV_ARCHIVE):
3153
curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \
32-
--progress-bar --output $(OPENCV_BASENAME).tar.gz
54+
--progress-bar --output $(OPENCV_ARCHIVE)
55+
56+
# The build also relies on virtualenv, because we make references to it.
57+
# Plus numpy is required to build OpenCV Python module.
58+
$(OPENCV_BUILD): $(OPENCV_ARCHIVE) virtualenv
3359
tar -xf $(OPENCV_BASENAME).tar.gz
3460
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)
61+
-D CMAKE_SHARED_LINKER_FLAGS=-l$(PYTHON_M) \
62+
-D BUILD_SHARED_LIBS=ON \
63+
-D BUILD_STATIC_LIBS=OFF \
64+
-D BUILD_DOCS=OFF \
65+
-D BUILD_OPENCV_APPS=OFF \
66+
-D BUILD_OPENCV_JAVA=OFF \
67+
-D BUILD_OPENCV_JAVA_BINDINGS_GENERATOR=OFF \
68+
-D BUILD_OPENCV_NONFREE=OFF \
69+
-D BUILD_OPENCV_PYTHON2=OFF \
70+
-D BUILD_OPENCV_PYTHON3=ON \
71+
-D BUILD_OPENCV_STITCHING=OFF \
72+
-D BUILD_OPENCV_SUPERRES=OFF \
73+
-D BUILD_OPENCV_TS=OFF \
74+
-D BUILD_PACKAGE=OFF \
75+
-D BUILD_PERF_TESTS=OFF \
76+
-D BUILD_TESTS=OFF \
77+
-D BUILD_WITH_DEBUG_INFO=OFF \
78+
-D OPENCV_SKIP_PYTHON_LOADER=ON \
79+
-D OPENCV_PYTHON$(PYTHON_MAJOR_VERSION)_INSTALL_PATH=$(SITE_PACKAGES_DIR) \
80+
-D PYTHON$(PYTHON_MAJOR_VERSION)_PACKAGES_PATH=$(SITE_PACKAGES_DIR) \
81+
-D PYTHON$(PYTHON_MAJOR_VERSION)_EXECUTABLE=$(PYTHON) \
82+
-D PYTHON$(PYTHON_MAJOR_VERSION)_INCLUDE_PATH=/usr/include/$(PYTHON_M)/ \
83+
-D PYTHON$(PYTHON_MAJOR_VERSION)_LIBRARIES=/usr/lib/x86_64-linux-gnu/lib$(PYTHON_M).so \
84+
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python$(PYTHON_MAJOR_VERSION) \
85+
-D WITH_1394=OFF \
86+
-D WITH_CUDA=OFF \
87+
-D WITH_CUFFT=OFF \
88+
-D WITH_GIGEAPI=OFF \
89+
-D WITH_GTK=OFF \
90+
-D WITH_JASPER=OFF \
91+
-D WITH_OPENEXR=OFF \
92+
-D WITH_PVAPI=OFF \
93+
-B$(OPENCV_BASENAME)/build -H$(OPENCV_BASENAME)
4394
cmake --build $(OPENCV_BASENAME)/build -- -j$(NPROC)
4495

45-
opencv_build: $(OPENCV_BUILD)
46-
47-
$(OPENCV_DEPLOY): opencv_build virtualenv
48-
cp $(OPENCV_BUILD) $(OPENCV_DEPLOY)
96+
$(OPENCV_DEPLOY): $(OPENCV_BUILD) virtualenv
97+
cp $(OPENCV_BUILD) $(SITE_PACKAGES_DIR)
4998

5099
opencv: $(OPENCV_DEPLOY)
51100

OpenCV.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
## Linux Camera support
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.
6-
Currently only OpenCV2 works with Kivy on Linux (see https://github.com/kivy/kivy/issues/5404).
76

87
Use the [Makefile](Makefile) provided to compile and install OpenCV library.
98
```
109
make system_dependencies
11-
make opencv_build
12-
```
13-
Then copy your compiled `cv2.so` to your virtualenv:
14-
```
15-
cp opencv-*/build/lib/cv2.so venv/lib/python2.7/site-packages/cv2.so
10+
make opencv
1611
```
12+
It would build OpenCV and deploy it to your virtualenv.

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@
33
[![Build Status](https://secure.travis-ci.org/kivy-garden/garden.zbarcam.png?branch=develop)](http://travis-ci.org/kivy-garden/garden.zbarcam)
44

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

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

1010
## How to use
1111
Simply import and instanciate `ZBarCam` in your kvlang file and access its `symbols` property.
1212
```yaml
1313
#:import ZBarCam kivy.garden.zbarcam
14+
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
1415
BoxLayout:
1516
orientation: 'vertical'
1617
ZBarCam:
1718
id: zbarcam
1819
# optional, by default checks all types
19-
code_types: 'qrcode', 'ean13'
20+
code_types: ZBarSymbol.QRCODE, ZBarSymbol.EAN13
2021
Label:
21-
size_y: 20
22-
size_hint_y: None
23-
text: ", ".join([str(code) for code in zbarcam.codes])
22+
size_hint: None, None
23+
size: self.texture_size[0], 50
24+
text: ', '.join([str(symbol.data) for symbol in zbarcam.symbols])
2425
```
2526
2627
## Install
27-
Install system requirements (Ubuntu 16.04):
28+
29+
### Ubuntu
30+
Install system requirements (Ubuntu 18.04):
2831
```sh
2932
sudo apt install libzbar-dev
3033
```
@@ -35,12 +38,20 @@ garden install xcamera
3538
```
3639

3740
Install zbarcam:
41+
Via `garden`:
42+
```sh
43+
garden install --upgrade zbarcam
44+
```
45+
Via `pip`:
3846
```sh
39-
garden install zbarcam
47+
pip install --upgrade https://github.com/kivy-garden/garden.zbarcam/archive/develop.zip
4048
```
4149

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

52+
### Android
53+
Build for Android via buildozer, see [buildozer.spec](buildozer.spec).
54+
4455
## Contribute
4556
To play with the project, install system dependencies and Python requirements using the [Makefile](Makefile).
4657
```sh
@@ -49,6 +60,7 @@ make
4960
Then verify everything is OK by running tests.
5061
```sh
5162
make test
63+
make uitest
5264
```
5365

5466
## Troubleshooting
@@ -62,7 +74,7 @@ garden install xcamera
6274
### Android `ValueError: Empty module name`
6375
More likely an import issue in your `.kv` file.
6476
Try to `from zbarcam import ZBarCam` in your `main.py` to see the exact error.
65-
It's common to forget `pil` in `buildozer.spec` `requirements` section.
77+
It's common to forget `Pillow` in `buildozer.spec` `requirements` section.
6678

6779
## Credits
6880
I borrowed a lot of code from [tito/android-zbar-qrcode](https://github.com/tito/android-zbar-qrcode).

buildozer.spec

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ source.include_exts = py,png,jpg,kv,atlas
2222
#source.exclude_exts = spec
2323

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

2727
# (list) List of exclusions using pattern matching
2828
#source.exclude_patterns = license,images/*/*.jpg
@@ -31,14 +31,19 @@ source.include_exts = py,png,jpg,kv,atlas
3131
# version = 0.1
3232

3333
# (str) Application versioning (method 2)
34-
# version.regex = __version__ = ['"](.*)['"]
3534
version.regex = __version__ = ['"](.*)['"]
36-
# version.filename = %(source.dir)s/main.py
3735
version.filename = %(source.dir)s/zbarcam/version.py
3836
3937
# (list) Application requirements
4038
# comma seperated e.g. requirements = sqlite3,kivy
41-
requirements = kivy, pil, libiconv, libzbar, zbarlight>=2.1
39+
requirements =
40+
android,
41+
kivy==5fc5385,
42+
libiconv,
43+
libzbar,
44+
Pillow==5.2.0,
45+
python3,
46+
pyzbar==0.1.8
4247
4348
4449
# (str) Custom source folders for requirements
@@ -89,20 +94,22 @@ fullscreen = 0
8994
#android.presplash_color = #FFFFFF
9095
9196
# (list) Permissions
92-
#android.permissions = INTERNET
9397
android.permissions = CAMERA
9498
95-
# (int) Android API to use
96-
#android.api = 19
99+
# (int) Target Android API, should be as high as possible.
100+
android.api = 27
97101
98-
# (int) Minimum API required
99-
#android.minapi = 9
102+
# (int) Minimum API your APK will support.
103+
android.minapi = 21
100104
101105
# (int) Android SDK version to use
102-
#android.sdk = 20
106+
android.sdk = 20
103107
104108
# (str) Android NDK version to use
105-
#android.ndk = 9c
109+
android.ndk = 17c
110+
111+
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
112+
android.ndk_api = 21
106113
107114
# (bool) Use --private data storage (True) or --dir public storage (False)
108115
#android.private_storage = True
@@ -158,7 +165,6 @@ android.accept_sdk_license = True
158165
#android.gradle_dependencies =
159166
160167
# (str) python-for-android branch to use, defaults to master
161-
#p4a.branch = stable
162168
p4a.branch = master
163169
164170
# (str) OUYA Console category. Should be one of GAME or APP
@@ -206,7 +212,6 @@ android.arch = armeabi-v7a
206212
207213
# (str) The directory in which python-for-android should look for your own build recipes (if any)
208214
#p4a.local_recipes =
209-
p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
210215
211216
# (str) Filename to the hook for p4a
212217
#p4a.hook =
@@ -233,7 +238,7 @@ p4a.local_recipes = %(source.dir)s/python-for-android/recipes/
233238
[buildozer]
234239
235240
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
236-
log_level = 1
241+
log_level = 2
237242
238243
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
239244
warn_on_root = 1

dockerfiles/Dockerfile-android

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# docker run -it --rm zbarcam-android
1010
FROM ubuntu:18.04
1111

12+
ARG CI=false
1213
ENV USER="user"
1314
ENV HOME_DIR="/home/${USER}"
1415
ENV WORK_DIR="${HOME_DIR}" \
@@ -26,16 +27,30 @@ ENV LANG="en_US.UTF-8" \
2627
LANGUAGE="en_US.UTF-8" \
2728
LC_ALL="en_US.UTF-8"
2829

29-
# install system dependencies (required to setup all the tools)
30+
# install system dependencies
3031
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
32+
autoconf \
33+
automake \
34+
cmake \
35+
make \
36+
ca-certificates \
37+
curl \
38+
gettext \
39+
libffi-dev \
40+
libltdl-dev \
41+
libpython3.6-dev \
42+
libtool \
43+
file \
44+
openjdk-8-jdk \
45+
pkg-config \
46+
python3.6 \
47+
python3-setuptools \
48+
python-pip \
49+
python-setuptools \
50+
sudo \
51+
unzip \
52+
xz-utils \
53+
zip
3954

4055
# prepare non root env
4156
RUN useradd --create-home --shell /bin/bash ${USER}
@@ -49,8 +64,10 @@ WORKDIR ${WORK_DIR}
4964
# install buildozer and dependencies
5065
RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk
5166
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
67+
# enforces buildozer master (cf880a3) until next release
68+
RUN pip install --upgrade https://github.com/kivy/buildozer/archive/cf880a3.zip
5469

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

0 commit comments

Comments
 (0)