From 9ed4ad6d85ed76abf211e7501b3130c9c047fb95 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 17 Mar 2019 01:56:05 +0100 Subject: [PATCH] Set workaround environment variable before importing OpenCV --- platypush/plugins/camera/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/platypush/plugins/camera/__init__.py b/platypush/plugins/camera/__init__.py index 6384b7d61f..dbba08a014 100644 --- a/platypush/plugins/camera/__init__.py +++ b/platypush/plugins/camera/__init__.py @@ -4,6 +4,10 @@ import shutil import threading import time +# 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 +os.environ['OPENCV_VIDEOIO_PRIORITY_MSMF'] = '0' + import cv2 from datetime import datetime @@ -136,11 +140,6 @@ 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)