community
community copied to clipboard
Slow start with opencv on Windows 10 because of missing parameter
Software Versions
- Python: 3.10.9
- OS: Windows 10
- Kivy: 2.1.0
- Kivy installation method: pip (poetry)
Describe the bug
On Windows 10, when using a Camera, the application is very slow to start.
Changing this line like this:
elif self.opencvMajorVersion in (2, 3, 4):
# create the device
- self._device = cv2.VideoCapture(self._index)
+ self._device = cv2.VideoCapture(self._index, cv2.CAP_DSHOW)
fixes the issue for me.
Expected behavior The application start time should not be affected noticeably.
To Reproduce
The camera example is enough. Launching it without the fix takes 25 seconds on my machine, and 4 seconds without.
Additional context
Tested with opencv-python version 4.7.0.72.
Sources for the given fix:
- https://stackoverflow.com/questions/72670286/camera-in-kivy-with-opencv-takes-a-lot-of-time-to-load
- https://www.reddit.com/r/learnpython/comments/oxo3gd/why_do_i_have_to_use_cv2cap_dshow/
I could not find documentation regarding this change, unfortunately.
I guess can be fixed via https://github.com/kivy/kivy/pull/8159 ?
Targeting that for 2.3.0