Last active
December 21, 2022 20:20
-
-
Save manifoldhiker/8384a348a87ae555319c289353f7a5dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tqdm.auto import tqdm | |
import cv2 | |
import torch | |
def read_video(file): | |
capture = cv2.VideoCapture(file) | |
fps = capture.get(cv2.CAP_PROP_FPS) | |
n_frames = capture.get(cv2.CAP_PROP_FRAME_COUNT) | |
frames = [] | |
for _ in tqdm(np.arange(n_frames)): | |
success, image_cv = capture.read() | |
if not success: | |
break | |
frame = cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB) | |
frame = torch.tensor(frame/255, dtype=torch.float32) | |
frames.append(frame.permute(2,0,1)[None]) | |
return frames, fps, n_frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.