From 3fe51f64821c42f89894e3d4c3737a746087f526 Mon Sep 17 00:00:00 2001 From: ATATC Date: Mon, 15 Jul 2024 18:20:50 +0800 Subject: [PATCH] Added a PIL interface. (#284) --- leads_video/camera.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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()