I have been trying to make an android apk in kivy to access mobile camera through opencv, but my application crashes in my phone. It is probably not able to access my phone's camera!
import imp
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDRaisedButton
from kivy.uix.image import Image
from kivy.clock import Clock
import cv2
from kivy.graphics.texture import Texture
class MainApp(MDApp):
def build(self):
layout = MDBoxLayout(orientation='vertical')
self.image = Image()
layout.add_widget(self.image)
layout.add_widget(MDRaisedButton(
text='Click Here',
pos_hint={'center_x':.5,'center_y':.5},
size_hint=(None,None))
)
self.capture=cv2.VideoCapture(0)
Clock.schedule_interval(self.load_video, 1.0/30.0)
return layout
def load_video(self, *args):
ret, frame= self.capture.read()
self.frame=frame
buffer=cv2.flip(frame, 0).tostring()
texture=Texture.create(size=(frame.shape[1],frame.shape[0]),colorfmt='bgr')
texture.blit_buffer(buffer, colorfmt='bgr',bufferfmt='ubyte')
self.image.texture=texture
if __name__ == '__main__':
MainApp().run()
Also the changes I have made in my buildozer.spec folder are as follows: