Created
February 8, 2021 21:47
-
-
Save cmower/72dea84c5b8c1d6ef1823bb73b61b2e0 to your computer and use it in GitHub Desktop.
Split each frame of a video into individual images.
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
import cv2 | |
"""Assumes video is called myvideo.MOV in the current directory and there | |
exists a directory called images/ in the same directory.""" | |
filename = 'myvideo.MOV' | |
cap = cv2.VideoCapture(filename) | |
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) | |
fc = 0 | |
ret = True | |
while (fc < frame_count and ret): | |
ret, frame = cap.read() | |
if ret: | |
new_filename = f'./images/myvideo_{fc}.png' | |
cv2.imwrite(new_filename, frame) | |
fc += 1 | |
print(f"{fc}/{frame_count}\r", flush=True, end='') | |
print("\rComplete", end=' ') | |
cap.release() | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment