From 1deabbb5684853999f4d5049c882b436d1561fb7 Mon Sep 17 00:00:00 2001 From: James Hodgson Date: Fri, 7 Oct 2022 17:24:29 +0100 Subject: [PATCH] #22 Fix rounding not happening --- README.md | 2 +- src/picam/picam.py | 8 ++++++-- src/picam/picam1.py | 10 +--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3df0678..2de79ce 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Specifies the camera type (`picam` interface implementation) to use. ### `capture_resolution` Specifies the resolution of the photos to take. -For picam1 implementation (and maybe more!), the X value will be rounded up to a multiple of 32, and the Y value to a multiple of 16, otherwise we'll get bugs due to the behaviour described in the [docs](https://picamera.readthedocs.io/en/release-1.13/recipes2.html#unencoded-image-capture-yuv-format) +The X value will be rounded up to a multiple of 32, and the Y value to a multiple of 16, otherwise we'll get bugs due to the behaviour described in the [docs](https://picamera.readthedocs.io/en/release-1.13/recipes2.html#unencoded-image-capture-yuv-format) ### `preview_resolution` diff --git a/src/picam/picam.py b/src/picam/picam.py index 5327493..4672efb 100644 --- a/src/picam/picam.py +++ b/src/picam/picam.py @@ -1,3 +1,5 @@ +from utils.utils import round_resolution + class PiCam: def __init__(self, config: dict): self.capture_resolution = config["capture_resolution"] @@ -8,14 +10,16 @@ class PiCam: :param resolution: New resolution for camera captures """ - self.capture_resolution = resolution + rounded_resolution = round_resolution(resolution, (32, 16)) + self.capture_resolution = rounded_resolution def set_preview_resolution(self, resolution: "tuple[int, int]") -> None: """Set resolution for camera preview (viewfinder) :param resolution: New resolution for camera preview """ - self.preview_resolution = resolution + rounded_resolution = round_resolution(resolution, (32, 16)) + self.preview_resolution = rounded_resolution def capture(self) -> bytearray: """Capture an image diff --git a/src/picam/picam1.py b/src/picam/picam1.py index f922752..d699c98 100644 --- a/src/picam/picam1.py +++ b/src/picam/picam1.py @@ -1,5 +1,4 @@ from picam.picam import PiCam -from utils.utils import round_resolution from io import BytesIO from picamera import PiCamera @@ -23,17 +22,10 @@ class PiCam1(PiCam): self.camera.resolution = resolution def set_preview_resolution(self, resolution: "tuple[int, int]") -> None: - rounded_resolution = round_resolution(resolution, (32, 16)) - - super().set_preview_resolution(rounded_resolution) + super().set_preview_resolution(resolution) self.set_camera_resolution(self.preview_resolution) - def set_capture_resolution(self, resolution: "tuple[int, int]") -> None: - rounded_resolution = round_resolution(resolution, (32, 16)) - - return super().set_capture_resolution(rounded_resolution) - def init_camera(self) -> None: """Initialize picamera camera object""" self.camera = PiCamera(resolution=self.preview_resolution)