diff --git a/leads_video/camera.py b/leads_video/camera.py index 8db1674d..13ca3a21 100644 --- a/leads_video/camera.py +++ b/leads_video/camera.py @@ -1,6 +1,6 @@ from typing import override as _override -from PIL.Image import fromarray as _fromarray +from PIL.Image import fromarray as _fromarray, Image as _Image from cv2 import VideoCapture as _VideoCapture, cvtColor as _cvtColor, COLOR_BGR2RGB as _COLOR_BGR2RGB from numpy import ndarray as _ndarray, pad as _pad, array as _array @@ -51,6 +51,9 @@ def read(self) -> _ndarray | None: def read_numpy(self) -> _ndarray | None: return self.read() + def read_pil(self) -> _Image | None: + return None if (frame := self.read_numpy()) is None else _fromarray(frame) + @_override def close(self) -> None: self._video_capture.release()