going in the right direction.

This commit is contained in:
didier amyot committed 2024-01-20 19:13:58 -05:00
1 parent b69b33ee59
commit d716ba80f7
4 files changed
+135 -3

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import contextlib
import time
import cv2
def create_video_writer(video_cap, output_filename):
# grab the width, height, and fps of the frames in the video stream.
frame_width = int(video_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(video_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(video_cap.get(cv2.CAP_PROP_FPS))
# initialize the FourCC and a video writer object
fourcc = cv2.VideoWriter_fourcc(*'MP4V')
writer = cv2.VideoWriter(output_filename, fourcc, fps,
(frame_width, frame_height))
return writer
def iter_frames(video_cap):
while 1:
ret, frame = video_cap.read()
if not ret:
return
yield frame
@contextlib.contextmanager
def time_tracker():
start = time.monotonic()
yield
end = time.monotonic()
print(f"Time to process 1 frame: {(end-start) * 1000:.0f} milliseconds")