Skip to content
This repository was archived by the owner on Oct 15, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions video_to_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Importing all necessary libraries
import cv2
import os

# Read the video from specified path
cam = cv2.VideoCapture("11.mp4")

try:

# creating a folder named data
if not os.path.exists('data'):
os.makedirs('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/frames' + str(currentframe) + '.jpg'
print ('Creating...' + name)

# writing the extracted images
frame=cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
frame=cv2.resize(frame,(400,400))
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()