There is no cv2 module in apk [closed]

asked 2019-04-13 05:55:46 -0600

Good afternoon, there is a small application written using python, kivy and opencv. The buildozer builds without errors, but when I launch the application on the phone it crashes with the following error:

04-12 18:44:54.848 5697 5739 I python : File "/home/max/desktop/finish/.buildozer/android/app/main.py", line 13, in module

04-12 18:44:54.848 5697 5739 I python : ModuleNotFoundError: No module named 'cv2'

Opencv is installed, I use PyCharm for writing code. What could be the problem?

requirements = python3, kivy, numpy, opencv

code(if necessary):

import kivy.core.text
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.scrollview import ScrollView
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.base import runTouchApp
from kivy.clock import Clock
from kivy.uix.image import Image
import time
import cv2
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics.texture import Texture

Builder.load_string('''<MainScreen>:               
    BoxLayout:
        orientation: "vertical"
        KivyCamera:
        Label:
            height: 20
            size_hint_y: None
            text: 'Cam_01'
    BoxLayout:
        orientation: "horizontal"
        height: 50
        size_hint_y: None
        Button:
            text: "Options"
            size_hint_y: None
            width: 150
            height: 50
            on_release: root.manager.current = 'options' 
<OptionsScreen>
    GridLayout:
        rows:3
        cols:1
        padding: 10
        spacing: 10
        Button:
            text: "Main Screen"
            size_hint_y: None
            width: 150
            height: 50
            on_release: root.manager.current = 'main'
        Button:
            text: "Alarm"
            size_hint_y: None
            width: 150
            height: 50
            on_release: root.manager.current = 'alarm'
        Button:
            text: "test"
            size_hint_y: None
            width: 150
            height: 50
<AlarmScreen>
    GridLayout:
        rows:3
        cols:1
        padding: 10
        spacing: 10
        Button:
            text: "Main Screen"
            size_hint_y: None
            width: 150
            height: 50
            on_release: root.manager.current = 'main'
        Button:
            text: "Options"
            size_hint_y: None
            width: 150
            height: 50
            on_release: root.manager.current = 'options'
        Button:
            text: "test"
            size_hint_y: None

            width: 150
            height: 50''')

class KivyCamera(Image):
    def __init__(self, **kwargs):
        super(KivyCamera, self).__init__(**kwargs)

        self.capture = cv2.VideoCapture(1)

        self.fps = 30

        Clock.schedule_interval(self.update, 1.0 / self.fps)

    def update(self, dt):
        ret, frame = self.capture.read()
        if ret:
            # convert it to texture
            buf1 = cv2.flip(frame, 0)
            buf = buf1.tostring()
            image_texture = Texture.create(
            size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
            image_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
        # display image from the texture
            self.texture = image_texture
            self.canvas.ask_update()

class MainScreen(Screen):
    pass

class OptionsScreen(Screen):
    pass


class AlarmScreen(Screen):
    pass

class Project_1App(App):
    def build(self):
        screenManager = ScreenManager()
        screenManager.add_widget(MainScreen(name="main"))
        screenManager.add_widget(OptionsScreen(name="options"))
        screenManager.add_widget(AlarmScreen(name="alarm"))

        return screenManager

Project_1App().run()
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2019-04-13 06:09:56.879623

Comments

we probably cannot help you with it, try to ping the kivy folks, it's their pipeline.

berak gravatar imageberak ( 2019-04-13 06:09:15 -0600 )edit

But kivy is absolutely nothing to do with it. There is a problem in opencv and apk.

maxufimcev gravatar imagemaxufimcev ( 2019-04-13 06:14:31 -0600 )edit

kivy is the only way to run cv2 on android, and it's their apk (and their special cv2 build). none of it supported or maintained from opencv.

really, not a (usual) opencv problem, don't expect any help from here

berak gravatar imageberak ( 2019-04-13 06:20:37 -0600 )edit

try #kivyon irc.freenode.net.

if you get an answer, let's reopen this in case there's someone else with this problem (you're the 1st ever)

berak gravatar imageberak ( 2019-04-13 06:26:02 -0600 )edit
supra56 gravatar imagesupra56 ( 2019-04-13 09:21:46 -0600 )edit

@supra56, please do lookup, what kivy is or does ....

berak gravatar imageberak ( 2019-04-13 09:30:05 -0600 )edit

@berak. I know what is KIVY. maxufimcev is using pyCharm. It is nothing to do with opencv.

supra56 gravatar imagesupra56 ( 2019-04-13 10:15:33 -0600 )edit