Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions leads_video/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def write(self, payload: tuple[int, int] | None) -> None:

def transform(self, x: _ndarray) -> _ndarray:
height, width = x.shape[:-1]
target_ratio = self._resolution[1] / self._resolution[0]
resolution_width, resolution_height = self._resolution
target_ratio = resolution_height / resolution_width
target_height = int(target_ratio * width)
pad_left, pad_right, pad_top, pad_bottom = 0, 0, 0, 0
if height > target_height:
Expand All @@ -38,8 +39,8 @@ def transform(self, x: _ndarray) -> _ndarray:
else:
pad_top = (target_height - height) // 2
pad_bottom = target_height - height - pad_top
x = _pad(x, ((0, 0), (pad_top, pad_bottom), (pad_left, pad_right)))
return _array(_fromarray(x).resize(self._resolution))
return _array(_fromarray(_pad(x, ((pad_left, pad_right), (pad_top, pad_bottom), (0, 0)))).resize(
self._resolution))

@_override
def read(self) -> _ndarray | None:
Expand Down
2 changes: 1 addition & 1 deletion leads_video/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def base64_decode_image(x_base64: str) -> _Image | None:
try:
return _open(_BytesIO(_b64decode(x_base64))) if x_base64 else None
except (ValueError, TypeError, _UnidentifiedImageError):
return None
return


def base64_decode(x_base64: str) -> _ndarray | None:
Expand Down