Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy Opencv Android

I'm trying to build an example Android app based on Kivy and OpenCv:

import kivy
from kivy.uix.button import Button
import cv2
kivy.require('1.0.6') 


from kivy.app import App
from kivy.uix.label import Label


class MyApp(App):

    def build(self):
        return Button(text='Hello!',
                      background_color=(0, 0, 1, 1),  
                      font_size=150)


if __name__ == '__main__':
    MyApp().run()

When running this example on desktop, it works fine, nevertheless when I build the APK with buildozer and try to run it on the phone, the app opens and closes immediately. My buildozer settings are:

[app]

title = MyTest

package.name = kivycrash2

package.domain = org.test

source.dir = .

source.include_exts = py,png,jpg,kv,atlas

version = 0.1

requirements =  kivy, numpy, cv2

orientation = landscape

If I remove the "import cv2" from the code and also remove the cv2 and numpy requirements from buildozer, the generated apk runs fine on the phone.

Is it possible to make opencv work with Kivy on an Android device? Does buildozer use the opencv version installed on my system (opencv 3)?

Thank you.

like image 970
Vb Dev Avatar asked Mar 27 '16 21:03

Vb Dev


People also ask

Can we use OpenCV in Kivy?

It converts the opencv captures to kivy textures, so you can do every kind of cv transformations before displaying it to your kivy interface.

Can Kivy run on Android?

Kivy can be run on Android phones using the Kivy Launcher (from the Android store) or an APK can be build using Python for Android (see http://kivy.org/docs/guide/packaging-android.html).

Can Kivy be used for app development?

Kivy is a really interesting GUI framework that you can use to create desktop user interfaces and mobile applications on both iOS and Android.

Is Kivy fast?

Kivy runs on Android, iOS, Linux, macOS and Windows. Get started! Kivy has been built to be easy to use, cross-platform and fast.


1 Answers

To solve the immediate crash when running the apk on the phone, the buildozer.spec file must be setup as follows:

[app]

title = MyTest

package.name = kivycrash2

package.domain = org.test

source.dir = .

source.include_exts = py,png,jpg,kv,atlas

version = 0.1

requirements =  kivy, numpy, opencv

orientation = landscape

as suggested by @Fins

Thank you.

like image 195
Vb Dev Avatar answered Nov 09 '22 00:11

Vb Dev