can't open camera by index
See original GitHub issueI 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]))
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
VideoCapture can't open camera by index #19527 - GitHub
Running the following code on my raspberry pi 4b and OpenCV installed via "pip install opencv-python" I have no issues: import cv2 cam...
Read more >OpenCv error can't open camera through video capture
I got the same error. Try changing 0 to -1 cap = cv2.VideoCapture(-1). This solved the issue.
Read more >Cant open camera by index. What do i do to rectify this? - Reddit
It will output 2 lists, the first one will be camera streams that openCV can open and the latter will be all camera...
Read more >WSL - webcam USB : Can not open camera by index
I successful connect my Usb camerawith my Wsl2, but can not open the camera (venv) root@PC00070:~/Face_recognition_with_Flask# lsusb Bus 002 ...
Read more >VIDEOIO ERROR:V4L: Can't open camera by index 0
VIDEOIO ERROR:V4L : can't open camera by index 0. Since the runBot.sh runs from terminal and not with crontab, I tried changing the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding index as property, is the best way. I did tests and all good. Will make a PR later.
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.