Skip to content

Instantly share code, notes, and snippets.

@Shamim-38
Created April 17, 2023 09:18
Show Gist options
  • Save Shamim-38/43b7e9ea85b08e75997303a7b26fac22 to your computer and use it in GitHub Desktop.
Save Shamim-38/43b7e9ea85b08e75997303a7b26fac22 to your computer and use it in GitHub Desktop.
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
# Importing all necessary libraries
import cv2
import os
# Read the video from specified path
cam = cv2.VideoCapture("Video/Path/h.mp4") #Video path
try:
# creating a folder named data
if not os.path.exists('./drive/MyDrive/data'):
os.makedirs('./drive/MyDrive/data')
# if not created then raise error
except OSError:
print ('Error: Creating directory of data')
# frame
currentframe = 0
while(True):
# reading from frame
ret,frame = cam.read()
if ret:
# if video is still left continue creating images
name = './data/frame' + str(currentframe) + '.jpg'
print ('Creating...' + name)
# writing the extracted images
cv2.imwrite(name, frame)
# increasing counter so that it will
# show how many frames are created
currentframe += 1
else:
break
# Release all space and windows once done
cam.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment