Skip to content

Instantly share code, notes, and snippets.

@garybradski
Last active January 31, 2018 04:09
Show Gist options
  • Select an option

  • Save garybradski/7a8432083ccdbcb4ef3db31c22344da4 to your computer and use it in GitHub Desktop.

Select an option

Save garybradski/7a8432083ccdbcb4ef3db31c22344da4 to your computer and use it in GitHub Desktop.
AVI2PGM.py
import cv2
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('--video', help='path to video to convert to images.')
parser.add_argument('--out', help='path to output directory.')
args = parser.parse_args()
if not os.path.exists(args.out):
os.makedirs(args.out)
cap = cv2.VideoCapture(args.video)
ctr = 0
while True:
print(ctr)
ret, frame = cap.read()
print(frame.size)
if not frame.size:
break
#cv2.imshow('frame', frame)
#cv2.waitKey(10)
image_name = 'fg_%09d.png' % ctr
cv2.imwrite(args.out + '/' + image_name, frame)
ctr += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment