From a43508a743cc8157ac0e07dfdda2e3a98b6840c6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 10 Sep 2019 00:21:11 +0200 Subject: [PATCH] Do not import cv2 in camera.__init__ unless we specify a video_type that needs to be expanded. Otherwise we introduce the OpenCV dependency also for the camera.pi plugin --- platypush/plugins/camera/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/camera/__init__.py b/platypush/plugins/camera/__init__.py index e26f7cda9..5e666c3b0 100644 --- a/platypush/plugins/camera/__init__.py +++ b/platypush/plugins/camera/__init__.py @@ -110,15 +110,17 @@ class CameraPlugin(Plugin): :type flip: int """ - import cv2 super().__init__(**kwargs) self._default_frames_dir = os.path.join(Config.get('workdir'), 'camera', 'frames') self.default_device_id = device_id self.frames_dir = os.path.abspath(os.path.expanduser(frames_dir or self._default_frames_dir)) self.warmup_frames = warmup_frames - self.video_type = cv2.VideoWriter_fourcc(*video_type) \ - if isinstance(video_type, str) else video_type + self.video_type = video_type + + if isinstance(video_type, str): + import cv2 + self.video_type = cv2.VideoWriter_fourcc(*video_type) self.sleep_between_frames = sleep_between_frames self.max_stored_frames = max_stored_frames