kivy-garden / garden.zbarcam Goto Github PK
View Code? Open in Web Editor NEWMigrated to https://github.com/kivy-garden/zbarcam
Home Page: https://github.com/kivy-garden/zbarcam
License: MIT License
Migrated to https://github.com/kivy-garden/zbarcam
Home Page: https://github.com/kivy-garden/zbarcam
License: MIT License
Since we're now runnong on Python3 and opencv 4.0.1, the Makefile
should be update accordingly.
Verify on CI tool e.g. Travis that we can build an APK for Android, also related to #6
Setup some continuous integration testing using e.g. Travis, to verify the app build and tests pass on Linux.
Check that:
Recent CI Android build fail silently, see https://travis-ci.org/kivy-garden/garden.zbarcam/jobs/500909800
The fact that it's a silent failure is already tracked upstream kivy/buildozer#674
Relevant part of the log is:
�[32;1mThe command docker run -e DISPLAY -e CI -v /tmp/.X11-unix:/tmp/.X11-unix zbarcam-android buildozer android debug exited with 0.�[0m
�[32;1mLog:�[0m
�[0m�[1;34m# Check configuration tokens�[0m
�[0m�[1;31m# WARNING: Config token app android.sdk is deprecated and ignored, but you set value 20�[0m
�[0m�[1;34m# Ensure build layout�[0m
�[0m�[1;34m# Check configuration tokens�[0m
�[0m�[1;34m# Preparing build�[0m
�[0m�[1;34m# Check requirements for android�[0m
�[0m�[1;34m# Install platform�[0m
�[0m�[1;34m# Android ANT is missing, downloading�[0m
�[0m�[1;34m# Apache ANT installation done.�[0m
�[0m�[1;34m# Android SDK is missing, downloading�[0m
�[0m�[1;34m# Unpacking Android SDK�[0m
�[0m�[1;34m# Android SDK tools base installation done.�[0m
�[0m�[1;34m# Android NDK is missing, downloading�[0m
�[0m�[1;34m# Unpacking Android NDK�[0m
�[0m�[1;34m# Android NDK installation done.�[0m
�[0m�[1;34m# Installing/updating SDK platform tools if necessary�[0m
�[0m�[1;34m# Updating SDK build tools if necessary�[0m
�[0m�[1;34m# Downloading platform api target if necessary�[0m
�[0m�[1;34m# Android packages installation done.�[0m
�[0m�[1;34m# Check application requirements�[0m
�[0m�[1;34m# Check garden requirements�[0m
�[0m�[1;34m# Compile platform�[0m
�[0m�[1;31m# Command failed: /usr/bin/python -m pythonforandroid.toolchain create --dist_name=zbarcamdemo --bootstrap=sdl2 --requirements=kivy==5fc5385,libiconv,libzbar,Pillow==5.2.0,python3,pyzbar==0.1.8 --arch armeabi-v7a --copy-libs --local-recipes /home/user/python-for-android/recipes --color=always --storage-dir="/home/user/.buildozer/android/platform/build" --ndk-api=21�[0m
�[0m�[1;31m# ENVIRONMENT:�[0m
�[0m�[1;31m# DOCKERFILES_VERSION = 'master'�[0m
�[0m�[1;31m# USER = 'user'�[0m
�[0m�[1;31m# HOME = '/home/user'�[0m
�[0m�[1;31m# PATH = '/home/user/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'�[0m
�[0m�[1;31m# DISPLAY = ':99.0'�[0m
�[0m�[1;31m# LANG = 'en_US.UTF-8'�[0m
�[0m�[1;31m# ANDROIDMINAPI = '21'�[0m
�[0m�[1;31m# PACKAGES_PATH = '/home/user/.buildozer/android/packages'�[0m
�[0m�[1;31m# SHLVL = '1'�[0m
�[0m�[1;31m# DOCKERFILES_URL = 'https://raw.githubusercontent.com/AndreMiras/dockerfiles'�[0m
�[0m�[1;31m# CI = 'true'�[0m
�[0m�[1;31m# WORK_DIR = '/home/user'�[0m
�[0m�[1;31m# HOME_DIR = '/home/user'�[0m
�[0m�[1;31m# ANDROIDSDK = '/home/user/.buildozer/android/platform/android-sdk'�[0m
�[0m�[1;31m# LC_ALL = 'en_US.UTF-8'�[0m
�[0m�[1;31m# _ = '/home/user/.local/bin/buildozer'�[0m
�[0m�[1;31m# MAKEFILES_URL = 'https://raw.githubusercontent.com/AndreMiras/dockerfiles/master/buildozer_android_new'�[0m
�[0m�[1;31m# LANGUAGE = 'en_US.UTF-8'�[0m
�[0m�[1;31m# HOSTNAME = 'c6b4194fa373'�[0m
�[0m�[1;31m# ANDROIDNDK = '/home/user/.buildozer/android/platform/android-ndk-r17c'�[0m
�[0m�[1;31m# PWD = '/home/user'�[0m
�[0m�[1;31m# ANDROIDAPI = '27'�[0m
�[0m�[1;31m# �[0m
�[0m�[1;31m# Buildozer failed to execute the last command�[0m
�[0m�[1;31m# If the error is not obvious, please raise the log_level to 2�[0m
�[0m�[1;31m# and retry the latest command.�[0m
�[0m�[1;31m# In case of a bug report, please add a full log with log_level = 2�[0m
/home/travis/.travis/functions: line 524: 13408 Terminated travis_jigger "${!}" "${timeout}" "${cmd[@]}"
travis_time:end:0957fa5f:start=1551560605057767317,finish=1551560942441221289,duration=337383453972
�[0K�[32;1mThe command "travis_wait docker run -e DISPLAY -e CI -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND" exited with 0.�[0m
Done. Your build exited with 0.
Looks like the codes are not being detected on Android.
When trying to scan a lot of codes the app seems to be lagging, which means something is happening under the hood, but the code doesn't seem to get decoded somehow.
On Android the camera image is blurry, but we can still flash QR Code.
We could take a look at https://github.com/kivy-garden/garden.xcamera implementation to see if it could be used.
Spent a couple hours trying to figure out why video displayed fine on my desktop but nothing could decode before finding the following.
In _detect_qrcode_frame()
, the image to be decoded is generated via the following line:
pil_image = PIL.Image.frombytes(mode=fmt, size=size, data=image_data)
where fmt
is derived from texture.colorfmt
and image_data
from texture.pixels
.
Per Kivy docs, texture.colorfmt
:
Can be ‘rgba’ or ‘rgb’, ‘luminance’ or ‘luminance_alpha’. On desktop, additional values are available: ‘red’, ‘rg’.
However, per the same docs, texture.pixels
:
Get the pixels texture, in RGBA format only, unsigned byte. The origin of the image is at bottom left.
The format returned by texture.pixels
will always be RGBA. If however the format returned by texture.colorfmt
is e.g. RGB, decoding will fail, as the image will be mangled accordingly.
As such, it should just be changed to
pil_image = PIL.Image.frombytes(mode='RGBA', size=size, data=image_data)
since texture.pixels
is guaranteed to return in that format. This should work on all platforms (and eliminate the need for the iOS special case in that function as well).
On Linux the make opencv
takes ages. I haven't timed it, but I reckon we could easily improve compile time by disabling some unused features using make flags.
To see enabled flags, run cmake -L
from the build directory:
cd opencv-*/build/
cmake -L | grep =ON
Our docker container (Dockerfile-linux
) currently runs commands as root. It would be great to have them running as unprivileged user just like user normally do when they run a Python app.
Last APK release seems to be too large: https://github.com/kivy-garden/garden.zbarcam/releases/tag/20190303
It's over 55M when it should be way less than 30M.
Dissecting it I saw that for instance the opencv-4.0.1/
directory got shipped in even though it's in the source.exclude_dirs
list.
Make the project work on Android.
Also, it seems that there're currently no recipe for ZBar, see kivy/python-for-android#854
Since android API 26 update, we need to request runtime permissions.
It would be great if that could be done seamlessly zbarcam side so developer don't have to bother.
Give zbarlight 2.1 a go since it fixes Polyconseil/zbarlight#23
The camera image is rotated 90° anticlockwise.
Makes sure the application is running under Python3.
Verify this in a unit test (tox).
For dependencies installation and test running.
Since #4 is fixed, we'd like to make the test run as part of the CI
I can't use it for python 3(because of zbar). I found some libraries for decoding qr code for third version of language which don't use zbar. But I can't create right recipes for buildozer. May be you can help me? And we will add Python 3 support
[INFO]: Building Pillow for armeabi-v7a
[INFO]: Pillow apparently isn't already in site-packages
[INFO]: Building compiled components in Pillow
[INFO]: -> directory context /home/cis/scanner/garden.zbarcam/.buildozer/android/platform/build/build/other_builds/Pillow-python3/armeabi-v7a__ndk_target_21/Pillow
[INFO]: -> running python setup.py build_ext -v
Exception in thread background thread for pid 32603:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 1540, in wrap
fn(*args, **kwargs)
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 2459, in background_thread
handle_exit_code(exit_code)
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 2157, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
ErrorReturnCode_1:
RAN: /home/cis/scanner/garden.zbarcam/.buildozer/android/platform/build/build/other_builds/hostpython3/desktop/hostpython3/native-build/python setup.py build_ext -v
STDOUT:
Traceback (most recent call last):
File "setup.py", line 22, in
from setuptools import Extension, setup
ModuleNotFoundError: No module named 'setuptools'
STDERR:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in run_code
exec code in run_globals
File "/home/cis/scanner/garden.zbarcam/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1186, in
main()
File "/home/cis/scanner/garden.zbarcam/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1180, in main
ToolchainCL()
File "/home/cis/scanner/garden.zbarcam/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 663, in init
getattr(self, args.subparser_name.replace('-', ''))(args)
File "/home/cis/scanner/garden.zbarcam/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 152, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/cis/scanner/garden.zbarcam/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 205, in build_dist_from_args
args, "ignore_setup_py", False
File "pythonforandroid/build.py", line 555, in build_recipes
File "pythonforandroid/recipe.py", line 883, in build_arch
File "pythonforandroid/recipe.py", line 895, in build_compiled_components
File "pythonforandroid/logger.py", line 178, in shprint
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 863, in next
self.wait()
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/home/cis/.local/lib/python2.7/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /home/cis/scanner/garden.zbarcam/.buildozer/android/platform/build/build/other_builds/hostpython3/desktop/hostpython3/native-build/python setup.py build_ext -v
STDOUT:
Traceback (most recent call last):
File "setup.py", line 22, in
from setuptools import Extension, setup
ModuleNotFoundError: No module named 'setuptools'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.