definitively going somewhere.

This commit is contained in:
didier committed 2024-11-04 18:50:34 -05:00
1 parent d7017c756b
commit 152b3b9da5
4 files changed
+36 -27

No files matched your search

+18 -5
View File
@@ -1,6 +1,6 @@
import abc
from pathlib import Path
from dodgeballtracker.typing import VideoFrame
import cv2
def create_video_writer(video_cap: cv2.VideoCapture, output_filename: Path) -> cv2.VideoWriter:
@@ -23,35 +23,45 @@ def create_video_writer(video_cap: cv2.VideoCapture, output_filename: Path) -> c
class VideoWriter(abc.ABC):
@abc.abstractmethod
def write_frame(self, frame) -> None:
def write_frame(self, frame: VideoFrame) -> None:
pass
@abc.abstractmethod
def close(self) -> None:
pass
@abc.abstractmethod
def wait(self) -> bool:
pass
class NoopVideoWriter(VideoWriter):
def write_frame(self, frame) -> None:
def write_frame(self, frame: VideoFrame) -> None:
pass
def close(self) -> None:
pass
def wait(self) -> bool:
return False
class MP4VVideoWriter(VideoWriter):
def __init__(self, video_writer: cv2.VideoWriter) -> None:
self._video_writer = video_writer
def write_frame(self, frame) -> None:
def write_frame(self, frame: VideoFrame) -> None:
self._video_writer.write(frame)
def close(self) -> None:
self._video_writer.release()
cv2.destroyAllWindows()
def wait(self) -> bool:
return False #cv2.waitKey(1) == ord("q")
@classmethod
def from_frame(cls, input_: Path, output: Path) -> VideoWriter:
video_cap = cv2.VideoCapture(str(input_))
@@ -62,6 +72,9 @@ class MP4VVideoWriter(VideoWriter):
class MP4VVideoWriterWithFrame(MP4VVideoWriter):
def write_frame(self, frame) -> None:
def write_frame(self, frame: VideoFrame) -> None:
super().write_frame(frame)
cv2.imshow("Frame", frame)
def wait(self) -> bool:
return cv2.waitKey(1) == ord("q")