Created
March 15, 2021 10:44
-
-
Save Shreyz-max/5e792c7f1e773fd4b93443f28970168e to your computer and use it in GitHub Desktop.
extract 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
def video_to_frames(video): | |
path = os.path.join(config.test_path, 'temporary_images') | |
if os.path.exists(path): | |
shutil.rmtree(path) | |
os.makedirs(path) | |
video_path = os.path.join(config.test_path, 'video', video) | |
count = 0 | |
image_list = [] | |
# Path to video file | |
cap = cv2.VideoCapture(video_path) | |
while cap.isOpened(): | |
ret, frame = cap.read() | |
if ret is False: | |
break | |
cv2.imwrite(os.path.join(config.test_path, 'temporary_images', 'frame%d.jpg' % count), frame) | |
image_list.append(os.path.join(config.test_path, 'temporary_images', 'frame%d.jpg' % count)) | |
count += 1 | |
cap.release() | |
cv2.destroyAllWindows() | |
return image_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment