Skip to content

Instantly share code, notes, and snippets.

@alpercalisir
Last active December 30, 2018 20:17
Show Gist options
  • Save alpercalisir/260898bbbd6592283ed82c183f54ef93 to your computer and use it in GitHub Desktop.
Save alpercalisir/260898bbbd6592283ed82c183f54ef93 to your computer and use it in GitHub Desktop.
Split video by frame
import cv2
import numpy as np
import os
cap = cv2.VideoCapture('IMG_4230.MOV')
if not os.path.exists('training_images'):
os.makedirs('training_images')
userid = 'x'
if not os.path.exists('training_images/'+userid):
os.makedirs('training_images/'+userid)
count=0
name_counter = 0
success=True
while count<1800:
ret, frame = cap.read()
name = './training_images/'+userid+ '/frame' + str(name_counter) +'_'+userid+ '.jpg'
print ('Creating...' + name)
if count%30==0:
name_counter += 1
cv2.imwrite(name, frame)
count += 1
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment