#22 Begin python rework

This commit is contained in:
James Hodgson
2022-10-07 14:40:39 +01:00
parent 97adf57e2e
commit 783eff7636
9 changed files with 204 additions and 65 deletions

53
src/picam/picam1.py Normal file
View File

@@ -0,0 +1,53 @@
from picam import PiCam
from picamera import PiCamera
class PiCam1(PiCam):
"""Implementation of PiCam class using legacy picamera module"""
def __init__(self, config: dict):
super().__init__(config)
self.init_camera()
def __del__(self):
"""Destructor - cleans up picamera"""
self.close_camera()
def set_camera_resolution(self, resolution: "tuple[int, int]") -> None:
"""Set resolution of active camera
:param resolution: Resolution to set camera to
"""
self.camera.resolution = resolution
def set_preview_resolution(self, resolution: "tuple[int, int]") -> None:
self.set_camera_resolution(resolution)
return super().set_preview_resolution(resolution)
def init_camera(self) -> None:
"""Initialize picamera camera object"""
self.camera = PiCamera(resolution=self.preview_resolution)
def close_camera(self) -> None:
"""Close picamera camera object"""
self.camera.close()
self.camera = None
def capture(self, preview: bool = False) -> bytes:
# Bytes to hold output buffer
out = bytes()
if not preview:
# If preview we'll already have the right resolution
self.set_camera_resolution(self.capture_resolution)
self.camera.capture(out, format='rgb', use_video_port=preview)
if not preview:
# If preview we'll already have the right resolution
self.set_camera_resolution(self.preview_resolution)
return out
def capture_preview(self) -> bytes:
return self.capture(preview=True)