made project vaguely in the shape of a python project
This commit is contained in:
1 parent
292c7762cd
commit
e26489bf9c
4 files changed
+1
-117
No files matched your search
@@ -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")
|
||||
Reference in new issue
Block a user