-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg_to_vid_ubuntu.py
41 lines (33 loc) · 1.13 KB
/
img_to_vid_ubuntu.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
import cv2
import numpy as np
import os
from os.path import isfile, join
def convert_frames_to_video(frame_array, pathIn, pathOut,fps):
global size
files = [f for f in os.listdir(pathIn) if isfile(join(pathIn, f))]
#for sorting the file names properly
files.sort(key = lambda x: int(x[0:-4]))
for i in range(len(files)):
filename=pathIn + files[i]
#reading each files
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
print(filename)
#inserting the frames into an image array
frame_array.append(img)
def main():
global out, frame_array
frame_array = []
for i in range(1, 4):
pathIn= 'img' + str(i) + '/'
pathOut = 'video.avi'
fps = 25.0
convert_frames_to_video(frame_array, pathIn, pathOut, fps)
out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
# writing to a image array
out.write(frame_array[i])
out.release()
if __name__=="__main__":
main()