Rodrigo_Cobo commited on
Commit
8eba3ec
1 Parent(s): d5307ab

fixed video issues

Browse files
Files changed (2) hide show
  1. WiggleResults/split.py +123 -0
  2. app.py +1 -1
WiggleResults/split.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from PIL import Image
3
+ import argparse
4
+ import imageio
5
+ import numpy as np
6
+ import cv2
7
+
8
+ parser = argparse.ArgumentParser(description='change to useful name')
9
+ parser.add_argument('--dim', default=256, type=int, help='dimention image')
10
+ args = parser.parse_args()
11
+
12
+ path = "."
13
+ ROOT_DIR = os.path.dirname(__file__)
14
+ dirs = os.listdir(ROOT_DIR)
15
+
16
+ dim = args.dim
17
+
18
+
19
+ def createVideo(array_pil, space_time = 5, name = "out_"):
20
+
21
+ size = array_pil[0].size[0]
22
+
23
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
24
+ video = cv2.VideoWriter(name +".mp4", # Filename
25
+ fourcc,
26
+ 30, # 10 frames per second is chosen as a demo, 30FPS and 60FPS is more typical for a YouTube video
27
+ (size,size) # The width and height come from the stats of image1
28
+ )
29
+
30
+ for image_pil in array_pil:
31
+ for i in range (0,space_time):
32
+ video.write(cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR))
33
+
34
+ video.release()
35
+
36
+
37
+ def gif_order (data, center=True):
38
+ gif = []
39
+ base = 1
40
+
41
+ #primera mitad
42
+ i = int((len(data)-2)/2)
43
+ while(i > base ):
44
+ gif.append(data[i])
45
+ #print(i)
46
+ i -= 1
47
+
48
+
49
+ #el del medio izq
50
+ gif.append(data[int((len(data)-2)/2) + 1])
51
+ #print(int((len(data)-2)/2) + 1)
52
+
53
+ #el inicial
54
+ if center:
55
+ gif.append(data[0])
56
+ #print(0)
57
+
58
+ # el del medio der
59
+ gif.append(data[int((len(data) - 2) / 2) + 2])
60
+ #print(int((len(data) - 2) / 2) +2)
61
+ #segunda mitad
62
+ i = int((len(data)-2)/2) + 3
63
+ while (i < len(data)):
64
+ gif.append(data[i])
65
+ #print(i)
66
+ i += 1
67
+ #print("---------")
68
+
69
+ invertedgif = gif[::-1]
70
+ invertedgif = invertedgif[1:]
71
+
72
+ gif = gif[1:] + invertedgif
73
+ #print(gif)
74
+ #for image in gif:
75
+ # image.show()
76
+ #gsdfgsfgf
77
+ return gif
78
+
79
+ print(" [*] Init gif generations!")
80
+ # This would print all the files and directories
81
+ for file in dirs:
82
+ if ".jpg" in file or ".png" in file:
83
+ rowImages = []
84
+ im = Image.open("./" + ROOT_DIR + '/' + file)
85
+ width, height = im.size
86
+ #im = im.convert('P')
87
+
88
+ #CROP (left, top, right, bottom)
89
+
90
+ pointleft = 3
91
+ pointtop = 3
92
+ i = 0
93
+ while (pointtop < height):
94
+ while (pointleft < width):
95
+ im1 = im.crop((pointleft, pointtop, dim+pointleft, dim+pointtop))
96
+ #h1 = im1.size[0] * 4
97
+ #im1 = im1.resize([h1,h1], Image.Resampling.LANCZOS)
98
+ rowImages.append(im1)
99
+ #im1.show()
100
+ pointleft+= dim+4
101
+ # Ya tengo todas las imagenes podria hacer el gif aca
102
+ rowImages = gif_order(rowImages,center=False)
103
+ createVideo(rowImages, 5, name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i))
104
+
105
+ name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i) + '.gif'
106
+ rowImages[0].save(name, save_all=True,format='GIF', append_images=rowImages[1:], optimize=True, duration=100, loop=0)
107
+
108
+
109
+ #print(rowImages)
110
+ pointtop += dim + 4
111
+ pointleft = 3
112
+ rowImages = []
113
+ i+=1
114
+ #im2 = im.crop((width / 2, 0, width, height))
115
+ # im2.show()
116
+
117
+ #im1.save("./2" + file[:-4] + ".png")
118
+ #im2.save("./" + file[:-4] + ".png")
119
+
120
+
121
+ # Deleted
122
+ #os.remove("data/" + file)
123
+ print(" [*] End gif generations!")
app.py CHANGED
@@ -61,7 +61,7 @@ def calculate_depth(model_type, gan_type, dim, slider, img):
61
  ])
62
  subprocess.run(["python", "WiggleResults/split.py", "--dim", dim])
63
 
64
- return [out_im,f'WiggleResults/' + name_output + '_0.gif', f'WiggleResults/' + "out" + '_0.mp4', f'WiggleResults/'+ name_output + '.jpg']
65
 
66
 
67
  with gr.Blocks() as demo:
 
61
  ])
62
  subprocess.run(["python", "WiggleResults/split.py", "--dim", dim])
63
 
64
+ return [out_im,f'WiggleResults/' + name_output + '_0.gif', f'WiggleResults/' + name_output + '_0.mp4', f'WiggleResults/'+ name_output + '.jpg']
65
 
66
 
67
  with gr.Blocks() as demo: