-
Notifications
You must be signed in to change notification settings - Fork 0
/
video2images.py
61 lines (47 loc) · 1.86 KB
/
video2images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 6 14:41:16 2019
@author: E442282
"""
import argparse
import sys
import cv2
import os
def getzoomout(image):
row, col= image.shape[:2]
bordersize=100
border=cv2.copyMakeBorder(image, top=bordersize, bottom=bordersize, left=bordersize,
right=bordersize, borderType= cv2.BORDER_CONSTANT,
value=[0,255,0] )
return border
def video2images(inputvideofile,outputimagesfolder):
vidcap = cv2.VideoCapture(inputvideofile)
returnvalue,image = vidcap.read() #returns true/false and an image
count = 0
while returnvalue:
returnvalue,image = vidcap.read()
if returnvalue==False:
break
filename=os.path.join(outputimagesfolder,"image%d.jpg" % count)
# image=getzoomout(image)
cv2.imwrite(filename, image) # save frame as JPEG/png file
print('Read next frame: ', returnvalue)
cv2.imshow('video',image)
if (cv2.waitKey(1) & 0xFF) == ord('q'): # Hit `q` to exit\
break
count += 1
vidcap.release()
cv2.destroyAllWindows()
print('\nCompleted Saving video frames to',outputimagesfolder)
def main(argv):
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True, help="Input video file ")
ap.add_argument("-o", "--output", required=False, default='.', help="output images directory")
args = vars(ap.parse_args())
inputvideofile = args['input']
outputimagesfolder = args['output']
# inputvideofile = 'popeye3.mp4'
# outputimagesfolder=r' C:\SAI\IIIT\2019_Spring\images'
video2images(inputvideofile,outputimagesfolder)
if __name__ == "__main__":
main(sys.argv[1:])