From 86a87f31072f967c84f2f12057292170b628399b Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 9 Sep 2019 14:56:37 +0200 Subject: [PATCH 1/5] Updates CHANGELOG.md to new tag format --- CHANGELOG.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53304fd..33655b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - Publish documentation to readthedocs, refs #18 - Publish to PyPI, refs #19 -## [20190303] +## [2019.0303] - Add Python3.6 support, refs #5 - Fully migrated Android from PIL to Pillow, refs #13 @@ -31,12 +31,12 @@ - Migrate from zbarlight to pyzbar, refs #32 - Migrate to Python3.6 and opencv 4, refs #33 -## [20190223] +## [2019.0223] - Fix zbarlight dependency in setup.py, refs #28 - Migrate to zbarlight 2.1, refs #18 -## [20190222] +## [2019.0222] - Provide Makefile, refs #15 - Setup continuous integration testing, refs #6, #14 @@ -46,31 +46,31 @@ - Using non-root Docker container, refs #27 - Run UI tests from Travis, refs #26 -## [20171220] +## [2017.1220] - Full screen camera - Kvlang refactoring - File tree refactoring -## [20171117] +## [2017.1117] - Integrated to kivy-garden -## [20171102] +## [2017.1102] - Add camera start/stop -## [20171020] +## [2017.1020] - Add Android autofocus, refs #2 - Fix Android rotation, refs #3 - Add animated demo gif -## [20171019] +## [2017.1019] - Add ZBar Android support, refs #1 - Add PIL/Pillow Android workaround -## [20171016] +## [2017.1016] - Initial release From 6dbca3c9223c8bc33eac0b18054c782cd62ebda2 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 9 Sep 2019 20:08:44 +0200 Subject: [PATCH 2/5] Uses `opencv-python` distribution from PyPI, fixes #23 OpenCV is now available over PyPI. --- .dockerignore | 1 - .gitignore | 1 - CHANGELOG.md | 4 +++ Makefile | 66 ++--------------------------------- OpenCV.md | 26 -------------- README.md | 11 ------ requirements/requirements.txt | 1 + setup.py | 1 + 8 files changed, 9 insertions(+), 102 deletions(-) delete mode 100644 OpenCV.md diff --git a/.dockerignore b/.dockerignore index 253b2ea..38d67d5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,3 @@ venv/ .buildozer/ .pytest_cache/ .tox/ -opencv-* diff --git a/.gitignore b/.gitignore index 7f5edc0..04bdc1f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ venv/ .tox/ .buildozer/ bin/ -opencv-* build/ dist/ *.egg-info/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 33655b3..b26547a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [Unreleased] + + - Use `opencv-python` from PyPI, refs #23 + ## [2019.0909] - Fix camera events not binded diff --git a/Makefile b/Makefile index 4502bff..c43d8c3 100644 --- a/Makefile +++ b/Makefile @@ -28,16 +28,6 @@ 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 -TMPDIR ?= /tmp -DOWNLOAD_DIR = $(TMPDIR)/downloads -OPENCV_VERSION=4.0.1 -OPENCV_BASENAME=opencv-$(OPENCV_VERSION) -OPENCV_ARCHIVE=$(OPENCV_BASENAME).tar.gz -OPENCV_ARCHIVE_PATH=$(DOWNLOAD_DIR)/$(OPENCV_ARCHIVE) -OPENCV_EXTRACT_PATH=$(DOWNLOAD_DIR)/$(OPENCV_BASENAME) -OPENCV_BUILD_LIB_DIR=$(OPENCV_EXTRACT_PATH)/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` @@ -46,7 +36,7 @@ ifeq ($(PYTHON_MAJOR_VERSION), 3) endif -all: system_dependencies virtualenv opencv +all: system_dependencies virtualenv venv: test -d venv || virtualenv -p python$(PYTHON_MAJOR_VERSION) venv @@ -61,56 +51,6 @@ ifeq ($(OS), Ubuntu) sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES) endif -$(OPENCV_ARCHIVE_PATH): - mkdir -p $(DOWNLOAD_DIR) - curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \ - --progress-bar --output $(OPENCV_ARCHIVE_PATH) - -# 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_PATH) virtualenv - tar -xf $(OPENCV_ARCHIVE_PATH) --directory $(DOWNLOAD_DIR) - cmake \ - -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_EXTRACT_PATH)/build -H$(OPENCV_EXTRACT_PATH) - cmake --build $(OPENCV_EXTRACT_PATH)/build -- -j$(NPROC) - -$(OPENCV_DEPLOY): $(OPENCV_BUILD) virtualenv - cp $(OPENCV_BUILD) $(SITE_PACKAGES_DIR) - -opencv: $(OPENCV_DEPLOY) - run/linux: virtualenv $(PYTHON) src/main.py @@ -156,5 +96,5 @@ clean: release/clean docs/clean find src/ -type d -name "__pycache__" -exec rm -r {} + find src/ -type d -name "*.egg-info" -exec rm -r {} + -clean/full: clean - rm -rf $(VENV_NAME) .tox/ $(DOWNLOAD_DIR) +clean/all: clean + rm -rf $(VENV_NAME) .tox/ diff --git a/OpenCV.md b/OpenCV.md deleted file mode 100644 index d5795da..0000000 --- a/OpenCV.md +++ /dev/null @@ -1,26 +0,0 @@ -# OpenCV - -## 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. - -Use the [Makefile](Makefile) provided to compile and install OpenCV library. -``` -make system_dependencies -make opencv -``` -It would build OpenCV and deploy it to your virtualenv. - -## Troubleshooting - -### Makefile `cp: cannot stat 'opencv-4.0.1/build/lib/python3/cv2*.so': No such file or directory` -Log: -``` -make[2]: Leaving directory '/tmp/trash/zbarcam/opencv-4.0.1/build' -make[1]: Leaving directory '/tmp/trash/zbarcam/opencv-4.0.1/build' -cp opencv-4.0.1/build/lib/python3/cv2*.so venv/lib/python3.7/site-packages -cp: cannot stat 'opencv-4.0.1/build/lib/python3/cv2*.so': No such file or directory -Makefile:97: recipe for target 'venv/lib/python3.7/site-packages/cv2*.so' failed -make: *** [venv/lib/python3.7/site-packages/cv2*.so] Error 1 -``` -Most likely you need to `pip install numpy` delete your opencv build and build again. diff --git a/README.md b/README.md index 42e77d4..6184a01 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,6 @@ Then import it in your Python code via: from kivy_garden.zbarcam import ZBarCam ``` -[OpenCV](OpenCV.md): -```sh -make opencv -``` - ### Android Build for Android via buildozer, see [buildozer.spec](buildozer.spec). @@ -77,9 +72,3 @@ You're missing the `xcamera` dependency. Install it as described in the install 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 `Pillow` in `buildozer.spec` `requirements` section. - -### OpenCV related -See [OpenCV.md](OpenCV.md). - -## Credits -I borrowed a lot of code from [tito/android-zbar-qrcode](https://github.com/tito/android-zbar-qrcode). diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2529428..9157bf2 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,6 @@ Kivy==1.11.1 Kivy-Garden==0.1.4 numpy==1.16.1 +opencv-python==4.1.1.26 Pillow==5.2.0 pyzbar==0.1.8 diff --git a/setup.py b/setup.py index 2a40a3c..ee223f1 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ def read(fname): 'install_requires': [ 'kivy', 'numpy', + 'opencv-python>=4', 'pillow', 'pyzbar', ], From 49cba2bef012d7b2d09a54a84955be6daaae9e91 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Tue, 10 Sep 2019 12:26:36 +0200 Subject: [PATCH 3/5] Makefile improvements and setup.py typo fix --- Makefile | 25 ++++++------------------- setup_meta.py | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index c43d8c3..8b9be5f 100644 --- a/Makefile +++ b/Makefile @@ -11,35 +11,22 @@ SOURCES=src/ tests/ setup.py setup_meta.py SPHINXBUILD=$(shell realpath venv/bin/sphinx-build) DOCS_DIR=doc SYSTEM_DEPENDENCIES= \ - build-essential \ - cmake \ - curl \ libpython$(PYTHON_VERSION)-dev \ libsdl2-dev \ libzbar-dev \ tox \ - virtualenv \ - wget + virtualenv OS=$(shell lsb_release -si) 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 -NPROC=`grep -c '^processor' /proc/cpuinfo` - - -ifeq ($(PYTHON_MAJOR_VERSION), 3) - PYTHON_M := $(PYTHON_M)m -endif all: system_dependencies virtualenv venv: - test -d venv || virtualenv -p python$(PYTHON_MAJOR_VERSION) venv + test -d venv || virtualenv -p $(PYTHON_WITH_VERSION) venv virtualenv: venv $(PIP) install Cython==0.28.6 @@ -63,16 +50,16 @@ uitest: virtualenv $(PIP) install -r requirements/test_requirements.txt PYTHONPATH=src $(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/ui/ -isort-check: virtualenv +lint/isort-check: virtualenv $(ISORT) --check-only --recursive --diff $(SOURCES) -isort-fix: virtualenv +lint/isort-fix: virtualenv $(ISORT) --recursive $(SOURCES) -flake8: virtualenv +lint/flake8: virtualenv $(FLAKE8) $(SOURCES) -lint: isort-check flake8 +lint: lint/isort-check lint/flake8 docs/clean: rm -rf $(DOCS_DIR)/build/ diff --git a/setup_meta.py b/setup_meta.py index c55169c..2e78f46 100644 --- a/setup_meta.py +++ b/setup_meta.py @@ -1,5 +1,5 @@ """ -Creates a distribution alias that just installs pyetheroll. +Creates a distribution alias that just installs kivy_garden.zbarcam. """ from setuptools import setup From 20940c10b9392741d8a299b4cf3a3b453df69a07 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Tue, 10 Sep 2019 21:56:34 +0200 Subject: [PATCH 4/5] Use new `xcamera` module We no longer rely on `garden`. --- CHANGELOG.md | 1 + Makefile | 13 +++++++------ README.md | 8 -------- buildozer.spec | 4 ++-- ...{test_requirements.txt => requirements-test.txt} | 0 requirements/requirements.txt | 1 + setup.py | 1 + src/kivy_garden/zbarcam/zbarcam.py | 4 ++-- tests/test_zbarcam.py | 1 - tests/ui/test_zbarcam_ui.py | 2 +- tox.ini | 6 +++--- 11 files changed, 18 insertions(+), 23 deletions(-) rename requirements/{test_requirements.txt => requirements-test.txt} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b26547a..137c91e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] + - Use new `xcamera` from PyPI - Use `opencv-python` from PyPI, refs #23 ## [2019.0909] diff --git a/Makefile b/Makefile index 8b9be5f..9b92db2 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,9 @@ venv: virtualenv: venv $(PIP) install Cython==0.28.6 $(PIP) install -r requirements/requirements.txt - $(GARDEN) install xcamera + +virtualenv/test: virtualenv + $(PIP) install -r requirements/requirements-test.txt system_dependencies: ifeq ($(OS), Ubuntu) @@ -46,17 +48,16 @@ run: run/linux test: $(TOX) -uitest: virtualenv - $(PIP) install -r requirements/test_requirements.txt +uitest: virtualenv/test PYTHONPATH=src $(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/ui/ -lint/isort-check: virtualenv +lint/isort-check: virtualenv/test $(ISORT) --check-only --recursive --diff $(SOURCES) -lint/isort-fix: virtualenv +lint/isort-fix: virtualenv/test $(ISORT) --recursive $(SOURCES) -lint/flake8: virtualenv +lint/flake8: virtualenv/test $(FLAKE8) $(SOURCES) lint: lint/isort-check lint/flake8 diff --git a/README.md b/README.md index 6184a01..1db05e4 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,6 @@ Install system requirements (Ubuntu 18.04): make system_dependencies ``` -Install garden requirements: -```sh -garden install --upgrade xcamera -``` - Install zbarcam: ```sh pip install --upgrade zbarcam @@ -65,9 +60,6 @@ make uitest ## Troubleshooting -### Install `Unable to import package 'kivy.garden.xcamera.XCamera'` -You're missing the `xcamera` dependency. Install it as described in the install instructions. - ### 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. diff --git a/buildozer.spec b/buildozer.spec index afd0f6f..28aed95 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -43,7 +43,8 @@ requirements = libzbar, Pillow==5.2.0, python3, - pyzbar==0.1.8 + pyzbar==0.1.8, + xcamera # (str) Custom source folders for requirements @@ -52,7 +53,6 @@ requirements = # (list) Garden requirements #garden_requirements = -garden_requirements = xcamera # (str) Presplash of the application #presplash.filename = %(source.dir)s/data/presplash.png diff --git a/requirements/test_requirements.txt b/requirements/requirements-test.txt similarity index 100% rename from requirements/test_requirements.txt rename to requirements/requirements-test.txt diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 9157bf2..4fcf674 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -4,3 +4,4 @@ numpy==1.16.1 opencv-python==4.1.1.26 Pillow==5.2.0 pyzbar==0.1.8 +xcamera diff --git a/setup.py b/setup.py index ee223f1..b11d386 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ def read(fname): 'opencv-python>=4', 'pillow', 'pyzbar', + 'xcamera', ], } diff --git a/src/kivy_garden/zbarcam/zbarcam.py b/src/kivy_garden/zbarcam/zbarcam.py index 9dc6b98..a138dde 100644 --- a/src/kivy_garden/zbarcam/zbarcam.py +++ b/src/kivy_garden/zbarcam/zbarcam.py @@ -3,10 +3,10 @@ import PIL from kivy.clock import Clock, mainthread -from kivy.garden.xcamera import XCamera from kivy.lang import Builder from kivy.properties import ListProperty from kivy.uix.anchorlayout import AnchorLayout +from kivy_garden.xcamera import XCamera from pyzbar import pyzbar from .utils import check_request_camera_permission, fix_android_image @@ -16,7 +16,7 @@ class CustomXCamera(XCamera): """ - Inherits from `kivy.garden.xcamera.XCamera`. + Inherits from `kivy_garden.xcamera.XCamera`. Overrides `_on_index()` to make sure the `kivy.core.camera.Camera` object is only created if permission are granted on Android. On other system, it's a noop calling the parent `_on_index()`. diff --git a/tests/test_zbarcam.py b/tests/test_zbarcam.py index 2ec73cd..0c4b035 100644 --- a/tests/test_zbarcam.py +++ b/tests/test_zbarcam.py @@ -4,7 +4,6 @@ import mock from kivy.base import EventLoop from kivy.core.image import Image - from kivy_garden.zbarcam import ZBarCam FIXTURE_DIR = os.path.join( diff --git a/tests/ui/test_zbarcam_ui.py b/tests/ui/test_zbarcam_ui.py index 024a43e..8016b0d 100644 --- a/tests/ui/test_zbarcam_ui.py +++ b/tests/ui/test_zbarcam_ui.py @@ -5,8 +5,8 @@ import mock from kivy.clock import Clock - from kivy_garden.zbarcam.zbarcam import ZBarCam + from main import DemoApp diff --git a/tox.ini b/tox.ini index 4621780..d6b1741 100644 --- a/tox.ini +++ b/tox.ini @@ -15,16 +15,16 @@ passenv = DISPLAY deps = :preinstall: Cython==0.28.6 -r{toxinidir}/requirements/requirements.txt - -r{toxinidir}/requirements/test_requirements.txt + -r{toxinidir}/requirements/requirements-test.txt commands = pytest --ignore tests/ui/ tests/ [testenv:pep8] deps = - -r{toxinidir}/requirements/test_requirements.txt + -r{toxinidir}/requirements/requirements-test.txt commands = flake8 src/ tests/ setup.py setup_meta.py [testenv:isort-check] deps = - -r{toxinidir}/requirements/test_requirements.txt + -r{toxinidir}/requirements/requirements-test.txt commands = isort --check-only --recursive --diff src/ tests/ setup.py setup_meta.py From bf26bb2636f9e4a0eec465370d44878537113912 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Wed, 11 Sep 2019 00:13:35 +0200 Subject: [PATCH 5/5] 2019.0910 --- CHANGELOG.md | 2 +- src/kivy_garden/zbarcam/version.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 137c91e..1b1bb3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [2019.0910] - Use new `xcamera` from PyPI - Use `opencv-python` from PyPI, refs #23 diff --git a/src/kivy_garden/zbarcam/version.py b/src/kivy_garden/zbarcam/version.py index 608dd00..1e8ec57 100644 --- a/src/kivy_garden/zbarcam/version.py +++ b/src/kivy_garden/zbarcam/version.py @@ -1,7 +1,7 @@ -__version__ = '2019.0909' +__version__ = '2019.0910' # The `__version_code__` is used for the F-Droid auto update and should match # the `versionCode` from the `build.gradle` file located in: # `.buildozer/android/platform/build/dists/zbarcamdemo/` # The auto update method used is the `HTTP`, see: # https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode -__version_code__ = 721202809 +__version_code__ = 721202810