AttributeError: 'NoneType' object has no attribute 'shape'

405 views
Skip to first unread message

Karthi V2246

unread,
Feb 12, 2023, 8:03:16 AM2/12/23
to Kivy users support
when i use Camera in my Widget , i stuck on thus erroe '' AttributeError: 'NoneType' object has no attribute 'shape''  

any one explain ?

Elliot Garbus

unread,
Feb 12, 2023, 11:08:38 AM2/12/23
to kivy-...@googlegroups.com

It could be a number of things.

  1. A missing dependency – Using the Camera on Windows requires the installation of a camera provider, if you are on Windows “pip install OpenCV-python” to install OpenCV as the camera provider.
  2. You could be using an ids dict before it was populated.  This can happen if you are accesing ids in the __init__(), instead access the ids dict in on_kv_post() or another method, not __init__()

 

Share some code and a more detailed error message for more help.  Here is a simple camera example:

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time


kv =
'''
CameraClick:
    orientation: 'vertical'
    Camera:
        id: camera
        resolution: (640, 480)
        play: True
    Button:
        text: 'Capture'
        size_hint_y: None
        height: '48dp'
        on_release: root.capture()
'''


class CameraClick(BoxLayout):
   
def capture(self):
        camera =
self.ids.camera
        time_str = time.strftime(
"%Y%m%d_%H%M%S")
        camera.export_to_png(
f'IMG_{time_str}.png')
       
print("Captured")


class TestCamera(App):
   
def build(self):
       
return Builder.load_string(kv)


TestCamera().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5f20fe6e-5266-47d7-acd1-a7639dfeb724n%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages