From e18f149100e9fdbaeb985cf4a78d0c57cbcf3bcf Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Thu, 29 Jul 2021 16:08:13 +0200 Subject: [PATCH] Allow resizing of image. --- controlpi_plugins/camera.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/controlpi_plugins/camera.py b/controlpi_plugins/camera.py index 5c42ebd..0e2790c 100644 --- a/controlpi_plugins/camera.py +++ b/controlpi_plugins/camera.py @@ -16,6 +16,7 @@ class Camera(BasePlugin): 'keep': {'type': 'integer'}, 'path': {'type': 'string'}, 'resolution': {'type': 'string'}, + 'resize': {'type': 'string'}, 'iso': {'type': 'integer'}}, 'required': ['pause', 'keep', 'path']} @@ -33,6 +34,15 @@ class Camera(BasePlugin): """Register plugin as bus client.""" self._images = collections.deque() self._capture = False + self._resolution = '1280x720' + if 'resolution' in self.conf: + self._resolution = self.conf['resolution'] + self._resize = '640x480' + if 'resize' in self.conf: + self._resize = self.conf['resize'] + self._iso = 200 + if 'iso' in self.conf: + self._iso = self.conf['iso'] sends = [MessageTemplate({'event': {'const': 'new image'}, 'image': {'type': 'string'}}), MessageTemplate({'image': {'type': 'string'}})] @@ -48,12 +58,8 @@ class Camera(BasePlugin): """Run camera.""" camera = picamera.PiCamera() stream = io.BytesIO() - camera.resolution = '1024x768' - if 'resolution' in self.conf: - camera.resolution = self.conf['resolution'] - camera.iso = 100 - if 'iso' in self.conf: - camera.iso = self.conf['iso'] + camera.resolution = self._resolution + camera.iso = self._iso try: while True: if self._capture: @@ -73,7 +79,7 @@ class Camera(BasePlugin): filepath = os.path.join(self.conf['path'], filename) await aiofiles.os.remove(filepath) - camera.capture(stream, 'jpeg') + camera.capture(stream, 'jpeg', resize=self._resize) filename = (datetime.datetime.utcnow() .strftime('%Y%m%d%H%M%S%f') + '.jpg') filepath = os.path.join(self.conf['path'], filename) -- 2.34.1