I'm facing this error when run the below code on android
File "/content/.buildozer/android/app/main.py", line 112, in on_tex 12-26 22:34:30.641 17922 19122 I python : File "/content/.buildozer/android/app/main.py", line 128, in frame_to_screen 12-26 22:34:30.642 17922 19122 I python : AttributeError: 'NoneType' object has no attribute 'blit_buffer'
it looks like _on_load method does not work
from kivy import platform
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics.texture import Texture
from kivy.uix.camera import Camera
from kivy.lang import Builder
import numpy as np
import cv2
Builder.load_file("main.kv")
class AndroidCamera(Camera):
camera_resolution = (640, 480)
counter = 0
def _camera_loaded(self, *largs):
self.texture = Texture.create(size=np.flip(self.camera_resolution), colorfmt='rgb')
self.texture_size = list(self.texture.size)
def on_tex(self, *l):
if self._camera._buffer is None:
return None
frame = self.frame_from_buf()
self.frame_to_screen(frame)
super(AndroidCamera, self).on_tex(*l)
def process_frame(self, frame):
r, g, b = cv2.split(frame)
frame = cv2.merge((b, g, r))
rows, cols, channel = frame.shape
M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 90, 1)
dst = cv2.warpAffine(frame, M, (cols, rows))
frame = cv2.flip(dst, 1)
if self.index == 1:
frame = cv2.flip(dst, -1)
return frame
class MyLayout(BoxLayout):
pass
class MyApp(App):
def build(self):
if platform == 'android':
from android.permissions import request_permissions, check_permission, Permission
if not check_permission(Permission.CAMERA):
request_permissions([Permission.CAMERA])
return MyLayout()
if __name__ == '__main__':
MyApp().run()