Code Monkey home page Code Monkey logo

garden.zbarcam's Introduction

garden.zbarcam

Build Status

Real time Barcode and QR Code scanner using the camera. It's built on top of Kivy and pyzbar.

screenshot

How to use

Simply import and instanciate ZBarCam in your kvlang file and access its symbols property.

#:import ZBarCam kivy.garden.zbarcam.ZBarCam
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
BoxLayout:
    orientation: 'vertical'
    ZBarCam:
        id: zbarcam
        # optional, by default checks all types
        code_types: ZBarSymbol.QRCODE, ZBarSymbol.EAN13
    Label:
        size_hint: None, None
        size: self.texture_size[0], 50
        text: ', '.join([str(symbol.data) for symbol in zbarcam.symbols])

Install

Ubuntu

Install system requirements (Ubuntu 18.04):

sudo apt install libzbar-dev

Install garden requirements:

garden install --upgrade xcamera

Install zbarcam: Via garden:

garden install --upgrade zbarcam

When installed with this method, the import command would be:

from kivy.garden.zbarcam import ZBarCam

Via pip:

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

When installed with this method, the import command would be:

from zbarcam import ZBarCam

You may also need to compile/install OpenCV manually, see OpenCV.md.

Android

Build for Android via buildozer, see buildozer.spec.

Contribute

To play with the project, install system dependencies and Python requirements using the Makefile.

make

Then verify everything is OK by running tests.

make test
make uitest

Troubleshooting

Install Unable to import package 'kivy.garden.xcamera.XCamera'

Missing the xcamera dependency, install it with:

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 Pillow in buildozer.spec requirements section.

OpenCV related

See OpenCV.md.

Credits

I borrowed a lot of code from tito/android-zbar-qrcode.

garden.zbarcam's People

Contributors

andremiras avatar darosior avatar gobig87 avatar siriusstarr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

garden.zbarcam's Issues

Seamlessly request camera permissions

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.

Codes not detected on Android

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.

setuptools not found while try build using Buildozer

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

Decoding failing due to wrong image mode being passed to PIL.

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).

Zbarcam for Python 3

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

Non-root docker container

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.

Investigate if OpenCV compile can be faster

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

Python3 support

Makes sure the application is running under Python3.
Verify this in a unit test (tox).

Setup basic unit testing

Check that:

  • flake8 is passing
  • isort is passing
  • the application is starting (under Linux) with no error

Travais Android build fails (silently)

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.