I was trying to develop an app which would use the feature of camera in kivy to click pictures and store them in a location.
But when the code is run every time an error is generated which point line number 103 of camera.py, which includes the resolution of the image.
Can you please help me in resolving the issue? Is it because of neumeric property of resolution?
Please find below the code:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
import time
Builder.load_string('''
<CameraClick>:
orientation: 'vertical'
Camera:
id: camera
resolution: (640, 480)
play: False
ToggleButton:
text: 'Play'
on_press: camera.play = not camera.play
size_hint_y: None
height: '48dp'
Button:
text: 'Capture'
size_hint_y: None
height: '48dp'
on_press: root.capture()
''')
class CameraClick(BoxLayout):
def capture(self):
'''
Function to capture the images and give them the names
according to their captured time and date.
'''
camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%S")
camera.export_to_png("IMG_{}.png".format(timestr))
print("Captured")
class TestCamera(App):
def build(self):
return CameraClick()
TestCamera().run()
The error which is displayed is
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\camera.py", line 103, in _on_index resolution=self.resolution, stopped=True)
Please find below the detailed error :
C:\Users\Rishi\AppData\Local\Programs\Python\Python37\python.exe C:/Users/Rishi/PycharmProjects/cam2/cam3.py
[INFO ] [Logger ] Record log in C:\Users\Rishi\.kivy\logs\kivy_20-06-16_0.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.2.0
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.7.3rc1 (tags/v3.7.3rc1:69785b2127, Mar 12 2019, 22:37:55) [MSC v.1916 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\python.exe"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[CRITICAL] [Camera ] Unable to find any valuable Camera provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
picamera - ModuleNotFoundError: No module named 'picamera'
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\camera\camera_picamera.py", line 18, in <module>
from picamera import PiCamera
gi - ModuleNotFoundError: No module named 'gi'
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\camera\camera_gi.py", line 10, in <module>
from gi.repository import Gst
opencv - ModuleNotFoundError: No module named 'cv2'
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\camera\camera_opencv.py", line 48, in <module>
import cv2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.6.0 - Build 26.20.100.7925'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) UHD Graphics 620'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 - Build 26.20.100.7925'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
Traceback (most recent call last):
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule
setattr(widget_set, key, value)
File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
File "kivy\properties.pyx", line 839, in kivy.properties.ListProperty.set
File "kivy\properties.pyx", line 544, in kivy.properties.Property.set
File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\camera.py", line 103, in _on_index
resolution=self.resolution, stopped=True)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Rishi/PycharmProjects/cam2/cam3.py", line 45, in <module>
TestCamera().run()
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line 829, in run
root = self.build()
File "C:/Users/Rishi/PycharmProjects/cam2/cam3.py", line 42, in build
return CameraClick()
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\boxlayout.py", line 145, in __init__
super(BoxLayout, self).__init__(**kwargs)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\layout.py", line 76, in __init__
super(Layout, self).__init__(**kwargs)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 361, in __init__
rule_children=rule_children)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 469, in apply_class_lang_rules
rule_children=rule_children)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 538, in apply
rule_children=rule_children)
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 707, in _apply_rule
e), cause=tb)
kivy.lang.builder.BuilderException: Parser: File "<inline>", line 6:
...
4: Camera:
5: id: camera
>> 6: resolution: (640,480)
7: play: False
8: ToggleButton:
...
TypeError: 'NoneType' object is not callable
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 700, in _apply_rule
setattr(widget_set, key, value)
File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
File "kivy\properties.pyx", line 839, in kivy.properties.ListProperty.set
File "kivy\properties.pyx", line 544, in kivy.properties.Property.set
File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "C:\Users\Rishi\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\camera.py", line 103, in _on_index
resolution=self.resolution, stopped=True)
Process finished with exit code 1