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.
It converts the opencv captures to kivy textures, so you can do every kind of cv transformations before displaying it to your kivy interface.
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).
Kivy is a really interesting GUI framework that you can use to create desktop user interfaces and mobile applications on both iOS and Android.
Kivy runs on Android, iOS, Linux, macOS and Windows. Get started! Kivy has been built to be easy to use, cross-platform and fast.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With