From 3af30075e3a66e034dfe2984a3d731aae60ac45d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 17 Mar 2019 01:26:06 +0100 Subject: [PATCH] Temporarily workaround for OpenCV >= 3.4.2 bug that doesn't properly release the video device --- platypush/plugins/camera/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platypush/plugins/camera/__init__.py b/platypush/plugins/camera/__init__.py index 900702b608..6384b7d61f 100644 --- a/platypush/plugins/camera/__init__.py +++ b/platypush/plugins/camera/__init__.py @@ -136,6 +136,10 @@ class CameraPlugin(Plugin): self._recording_threads = {} # device_id => Thread map self._recording_info = {} # device_id => recording info map + # Temporary workaround for bug on OpenCV >= 3.4.2 that doesn't + # properly release the device, see https://github.com/opencv/opencv/issues/12301#issuecomment-415801564 + if tuple(map(int, cv2.__version__.split('.'))) >= (3, 4, 2): + os.environ['OPENCV_VIDEOIO_PRIORITY_MSMF'] = '0' def _init_device(self, device_id, frames_dir=None, **info): self._release_device(device_id) @@ -172,6 +176,7 @@ class CameraPlugin(Plugin): if device_id in self._recording_info: del self._recording_info[device_id] + self.logger.info("Device {} released".format(device_id)) def _store_frame_to_file(self, frame, frames_dir, image_file):