#22 Fix distortion bug
This commit is contained in:
@@ -22,7 +22,10 @@ Specifies the camera type (`picam` interface implementation) to use.
|
||||
```
|
||||
|
||||
### `capture_resolution`
|
||||
Specifies the resolution of the photos to take
|
||||
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)
|
||||
|
||||
|
||||
### `preview_resolution`
|
||||
Specifies the resolution of the viewfinder. I've set this to the resolution of the hyperpixel4 display
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"camera_type": 1,
|
||||
"capture_resolution": [3464, 2309],
|
||||
"capture_resolution": [3000, 2000],
|
||||
"preview_resolution": [800, 480],
|
||||
"output_format": "JPEG",
|
||||
"output_extension": ".jpg",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from picam.picam import PiCam
|
||||
from utils.utils import round_resolution
|
||||
|
||||
from io import BytesIO
|
||||
from picamera import PiCamera
|
||||
@@ -22,8 +23,16 @@ class PiCam1(PiCam):
|
||||
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)
|
||||
rounded_resolution = round_resolution(resolution, (32, 16))
|
||||
|
||||
super().set_preview_resolution(rounded_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"""
|
||||
|
||||
18
src/utils/utils.py
Normal file
18
src/utils/utils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def round_value_up(value: int, multiple: int) -> int:
|
||||
"""Round value up to the nearest of the given multiple
|
||||
|
||||
:param value: Value to round
|
||||
:param multiple: Multiple to round the value up to
|
||||
:returns: Rounded value
|
||||
"""
|
||||
value_mod = value % multiple
|
||||
return value + (multiple - value_mod)
|
||||
|
||||
def round_resolution(resolution: "tuple[int, int]", multiples: "tuple[int, int]") -> "tuple[int, int]":
|
||||
"""Round resolution up to the nearest of the given multiples
|
||||
|
||||
:param resolution: Resolution to round
|
||||
:param multiples: Multiples to round the resolution values to
|
||||
:returns: Tuple containing rounded resolution
|
||||
"""
|
||||
return (round_value_up(resolution[0], multiples[0]), round_value_up(resolution[0], multiples[0]))
|
||||
Reference in New Issue
Block a user