Only import cv2 in the methods that require it (prevents camera.pi
and other camera derived plugins from failing if OpenCV is not installed)
This commit is contained in:
parent
fa9b816d06
commit
228e656da8
1 changed files with 8 additions and 2 deletions
|
@ -4,8 +4,6 @@ import shutil
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import cv2
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from platypush.config import Config
|
from platypush.config import Config
|
||||||
|
@ -112,6 +110,7 @@ class CameraPlugin(Plugin):
|
||||||
:type flip: int
|
:type flip: int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import cv2
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self._default_frames_dir = os.path.join(Config.get('workdir'), 'camera', 'frames')
|
self._default_frames_dir = os.path.join(Config.get('workdir'), 'camera', 'frames')
|
||||||
|
@ -135,6 +134,7 @@ class CameraPlugin(Plugin):
|
||||||
self._recording_info = {} # device_id => recording info map
|
self._recording_info = {} # device_id => recording info map
|
||||||
|
|
||||||
def _init_device(self, device_id, frames_dir=None, **info):
|
def _init_device(self, device_id, frames_dir=None, **info):
|
||||||
|
import cv2
|
||||||
self._release_device(device_id)
|
self._release_device(device_id)
|
||||||
|
|
||||||
if device_id not in self._devices:
|
if device_id not in self._devices:
|
||||||
|
@ -173,6 +173,8 @@ class CameraPlugin(Plugin):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _store_frame_to_file(frame, frames_dir, image_file):
|
def _store_frame_to_file(frame, frames_dir, image_file):
|
||||||
|
import cv2
|
||||||
|
|
||||||
if image_file:
|
if image_file:
|
||||||
filepath = image_file
|
filepath = image_file
|
||||||
else:
|
else:
|
||||||
|
@ -215,6 +217,8 @@ class CameraPlugin(Plugin):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
|
|
||||||
def _make_video_file(self, frames_dir, video_file, video_type):
|
def _make_video_file(self, frames_dir, video_file, video_type):
|
||||||
|
import cv2
|
||||||
|
|
||||||
files = self._get_stored_frames_files(frames_dir)
|
files = self._get_stored_frames_files(frames_dir)
|
||||||
if not files:
|
if not files:
|
||||||
self.logger.warning('No frames found in {}'.format(frames_dir))
|
self.logger.warning('No frames found in {}'.format(frames_dir))
|
||||||
|
@ -238,6 +242,7 @@ class CameraPlugin(Plugin):
|
||||||
max_stored_frames, color_transform, video_type,
|
max_stored_frames, color_transform, video_type,
|
||||||
scale_x, scale_y, rotate, flip):
|
scale_x, scale_y, rotate, flip):
|
||||||
|
|
||||||
|
import cv2
|
||||||
device = self._devices[device_id]
|
device = self._devices[device_id]
|
||||||
color_transform = getattr(cv2, self.color_transform)
|
color_transform = getattr(cv2, self.color_transform)
|
||||||
rotation_matrix = None
|
rotation_matrix = None
|
||||||
|
@ -343,6 +348,7 @@ class CameraPlugin(Plugin):
|
||||||
these parameters if you want to override the default configured ones.
|
these parameters if you want to override the default configured ones.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import cv2
|
||||||
device_id = device_id if device_id is not None else self.default_device_id
|
device_id = device_id if device_id is not None else self.default_device_id
|
||||||
if device_id in self._is_recording and \
|
if device_id in self._is_recording and \
|
||||||
self._is_recording[device_id].is_set():
|
self._is_recording[device_id].is_set():
|
||||||
|
|
Loading…
Reference in a new issue