'Getting AttributeError: 'NoneType' object has no attribute 'shape' error while woring in Kivy
I am exploring kivy to deploy my ml model. I have wrote the code to access the camera using kivy but I'm getting AttributeError: 'NoneType' object has no attribute 'shape' error. Can Anyone help me?
Here is the error:
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()
#frame load and frame initialize
self.image_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
Solution 1:[1]
I don't see a resolution anywhere in your code but when I ran into the same error using the example from Kivy documentation, I was able to fix it by changing my resolution from 640 x 480 to self.resolution
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user3554868 |