Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't open camera by index #55

Open
richierh opened this issue Jan 20, 2021 · 9 comments
Open

can't open camera by index #55

richierh opened this issue Jan 20, 2021 · 9 comments

Comments

@richierh
Copy link

I got this error while running my code


[INFO   ] [Camera      ] Provider: opencv(['camera_picamera', 'camera_gi'] ignored)
[ WARN:0] global /tmp/pip-req-build-ms668fyv/opencv/modules/videoio/src/cap_v4l.cpp (893) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
 Traceback (most recent call last):
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 705, in _apply_rule
     setattr(widget_set, key, value)
   File "kivy/weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
   File "kivy/properties.pyx", line 498, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 840, in kivy.properties.ListProperty.set
   File "kivy/properties.pyx", line 545, in kivy.properties.Property.set
   File "kivy/properties.pyx", line 600, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1154, in kivy._event.EventObservers._dispatch
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy_garden/xcamera/xcamera.py", line 85, in _on_index
     self._on_index_dispatch(*largs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy_garden/xcamera/xcamera.py", line 88, in _on_index_dispatch
     super()._on_index(*largs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/uix/camera.py", line 103, in _on_index
     self._camera = CoreCamera(index=self.index,
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/camera_opencv.py", line 70, in __init__
     super(CameraOpenCV, self).__init__(**kwargs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/__init__.py", line 70, in __init__
     self.init_camera()
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/camera_opencv.py", line 120, in init_camera
     self._resolution = (int(frame.shape[1]), int(frame.shape[0]))
 AttributeError: 'NoneType' object has no attribute 'shape'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "main.py", line 48, in <module>
     DemoApp().run()
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/app.py", line 949, in run
     self._run_prepare()
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/app.py", line 918, in _run_prepare
     self.load_kv(filename=self.kv_file)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/app.py", line 691, in load_kv
     root = Builder.load_file(rfilename)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 306, in load_file
     return self.load_string(data, **kwargs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 408, in load_string
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 663, in _apply_rule
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 663, in _apply_rule
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 663, in _apply_rule
     self._apply_rule(
   [Previous line repeated 3 more times]
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 661, in _apply_rule
     child.apply_class_lang_rules(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/uix/widget.py", line 463, in apply_class_lang_rules
     Builder.apply(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 541, in apply
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 663, in _apply_rule
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 661, in _apply_rule
     child.apply_class_lang_rules(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/uix/widget.py", line 463, in apply_class_lang_rules
     Builder.apply(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 541, in apply
     self._apply_rule(
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 710, in _apply_rule
     raise BuilderException(rule.ctx, rule.line,
 kivy.lang.builder.BuilderException: Parser: File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy_garden/xcamera/xcamera.kv", line 27:
 ...
      25:
      26:    id: camera
 >>   27:    resolution: 640, 480 # 1920, 1080
      28:    allow_stretch: True
      29:
 ...
 AttributeError: 'NoneType' object has no attribute 'shape'
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/lang/builder.py", line 705, in _apply_rule
     setattr(widget_set, key, value)
   File "kivy/weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
   File "kivy/properties.pyx", line 498, in kivy.properties.Property.__set__
   File "kivy/properties.pyx", line 840, in kivy.properties.ListProperty.set
   File "kivy/properties.pyx", line 545, in kivy.properties.Property.set
   File "kivy/properties.pyx", line 600, in kivy.properties.Property.dispatch
   File "kivy/_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
   File "kivy/_event.pyx", line 1154, in kivy._event.EventObservers._dispatch
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy_garden/xcamera/xcamera.py", line 85, in _on_index
     self._on_index_dispatch(*largs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy_garden/xcamera/xcamera.py", line 88, in _on_index_dispatch
     super()._on_index(*largs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/uix/camera.py", line 103, in _on_index
     self._camera = CoreCamera(index=self.index,
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/camera_opencv.py", line 70, in __init__
     super(CameraOpenCV, self).__init__(**kwargs)
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/__init__.py", line 70, in __init__
     self.init_camera()
   File "/home/cireng/.virtualenvs/kivypos/lib/python3.8/site-packages/kivy/core/camera/camera_opencv.py", line 120, in init_camera
     self._resolution = (int(frame.shape[1]), int(frame.shape[0]))
 

@richierh richierh reopened this Jan 20, 2021
@RafalGlombiowski
Copy link

I have the same error. I work on Linux Mint 19.3 and python 3.6.9.

@garantor
Copy link

garantor commented May 7, 2021

ran into same issue today

@garantor
Copy link

garantor commented May 7, 2021

installing kivy 2.1.0.dev0 from github fixes this issues for me, thanks

@HernanOsorio
Copy link

how can I access 'index' of xcamera in zbarcam.py from main.py and change the value?

@wanaxe
Copy link
Contributor

wanaxe commented Jun 8, 2022

how can I access 'index' of xcamera in zbarcam.py from main.py and change the value?

I have to drop the zbarcam package and copy the source code into my app folder. Then modify the xcamera property part (within zbarcam.py) from

@property
def xcamera(self):
    return self.ids['xcamera']

to

@property
def xcamera(self):
    xcamera = self.ids['xcamera']
    xcamera.index = 1
    # xcamera.resolution = (640, 480)
    return xcamera

If index = 1 doesn't work, you may try other values. In my case (3 cameras), 1 is not woking, but 0 & 2 & 4 working.

This is just a workaround to get my app working. There must be a better way.

@AndreMiras
Copy link
Collaborator

You can probably monkey patch it without rewriting the entire thing

@wanaxe
Copy link
Contributor

wanaxe commented Jun 8, 2022

Yeah, money patch is the way. Thank you so much!

Do you have any idea how those camera indices are assigned? I have to try-and error to figure it out.

@AndreMiras
Copy link
Collaborator

Great for the monkey patch.
Good question for the indices, I haven't looked into it.
But we may want to make that index parameter available as a property for easy overriding.
If anyone is interested for testing that and making a PR

@wanaxe
Copy link
Contributor

wanaxe commented Jun 8, 2022

Adding index as property, is the best way. I did tests and all good. Will make a PR later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants