from pathlib import Path
from cv2 import VideoCapture, imread
from .base import BaseCamera
[docs]class ImageFileCamera(BaseCamera):
[docs] def __init__(self, image_path: Path, **kwargs):
self.image_path = image_path
super().__init__(**kwargs)
[docs] def capture_frame(self):
return imread(str(self.image_path))
[docs]class VideoFileCamera(BaseCamera):
[docs] def __init__(self, video_path: Path, **kwargs):
super().__init__(**kwargs)
self.video_capture = self.get_video_capture(video_path)
[docs] def get_video_capture(self, video_path: Path):
return VideoCapture(str(video_path))
[docs] def capture_frame(self):
_, frame = self.video_capture.read()
return frame
[docs] def close(self):
super().close()
self.video_capture.release()