'AttributeError: 'NoneType' object has no attribute 'tostring' in application, but works fine in PC
I'm trying to make apk file from using python. This code is using cv2.VideoCapture(0) to make phone camera application. Here's my code
# Import kivy dependencies first
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
# Import kivy UX components
from kivy.uix.image import Image
# Import other kivy stuff
from kivy.clock import Clock
from kivy.graphics.texture import Texture
# Import other dependencies
import cv2
class CamApp(App):
def build(self):
self.vid = cv2.VideoCapture(0)
self.web_cam = Image()
layout = BoxLayout()
layout.add_widget(self.web_cam)
#self.capture = cv2.VideoCapture(0)
Clock.schedule_interval(self.update, 1.0 / 33.0)
self.vid.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
self.vid.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
#w = self.vid.get(cv2.CAP_PROP_FRAME_WIDTH)
#h = self.vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
#print("너비 {} 높이 {}".format(w, h))
return layout
def update(self, *args):
ret, frame = self.vid.read()
#frame = cv2.flip(frame, 0)
# Flip horizontal and convert image to texture
buf = cv2.flip(frame, 0).tostring()
img_texture = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
img_texture.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
self.web_cam.texture = img_texture
if __name__ == '__main__':
CamApp().run()
It works fine on PC and I used buildozer to make application. Here's my part of my buildozer.spec
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,opencv
Anyway, when I played the application I made, it shuts off after kivy loading page. So I used adb and got an error message
AttributeError: 'NoneType' object has no attribute 'tostring'
I can't understand why this error messaged showed up because it worked well in my PC. Please help me...
Thank you!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
