Rodrigo_Cobo commited on
Commit
604f38b
1 Parent(s): cc62c8c

new way of creating mp4

Browse files
Files changed (2) hide show
  1. WiggleResults/split.py +9 -15
  2. app.py +7 -2
WiggleResults/split.py CHANGED
@@ -4,6 +4,7 @@ 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')
@@ -17,21 +18,14 @@ 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):
@@ -100,7 +94,7 @@ for file in dirs:
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)
 
4
  import imageio
5
  import numpy as np
6
  import cv2
7
+ import mediapy as media
8
 
9
  parser = argparse.ArgumentParser(description='change to useful name')
10
  parser.add_argument('--dim', default=256, type=int, help='dimention image')
 
18
 
19
 
20
  def createVideo(array_pil, space_time = 5, name = "out_"):
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ ar_im = []
23
+ for j in range(3):
24
+ for image in array_pil:
25
+ for i in range (0,space_time):
26
+ ar_im.append(np.array(image))
27
+
28
+ media.write_video(name +".mp4" , ar_im, fps=30, qp=18)
29
 
30
 
31
  def gif_order (data, center=True):
 
94
  pointleft+= dim+4
95
  # Ya tengo todas las imagenes podria hacer el gif aca
96
  rowImages = gif_order(rowImages,center=False)
97
+ createVideo(rowImages, 3, name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i))
98
 
99
  name = "./" + ROOT_DIR + '/' + file[:-4] + "_" + str(i) + '.gif'
100
  rowImages[0].save(name, save_all=True,format='GIF', append_images=rowImages[1:], optimize=True, duration=100, loop=0)
app.py CHANGED
@@ -10,6 +10,7 @@ import subprocess
10
 
11
  def calculate_depth(model_type, gan_type, dim, slider, img):
12
 
 
13
  if not os.path.exists('temp'):
14
  os.system('mkdir temp')
15
 
@@ -50,6 +51,7 @@ def calculate_depth(model_type, gan_type, dim, slider, img):
50
  formatted = (output * 255.0 / np.max(output)).astype('uint8')
51
  out_im = Image.fromarray(formatted)
52
  out_im.save("Images/Input-Test/1_d.png", "PNG")
 
53
 
54
  c_images = '1'
55
  name_output = 'out'
@@ -61,7 +63,10 @@ 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/' + name_output + '_0.mp4', f'WiggleResults/'+ name_output + '.jpg']
 
 
 
65
 
66
 
67
  with gr.Blocks() as demo:
@@ -82,7 +87,7 @@ with gr.Blocks() as demo:
82
  out = [gr.Image(type="pil", label="depth_estimation")]
83
  with gr.Row():
84
  out.append(gr.Image(type="file", label="Output_wiggle_gif"))
85
- out.append(gr.Video(label="Output_wiggle_video", format='mp4'))
86
  out.append(gr.Image(type="file", label="Output_images"))
87
  btn = gr.Button("Calculate depth + Wiggle")
88
  btn.click(fn=calculate_depth, inputs=inp, outputs=out)
 
10
 
11
  def calculate_depth(model_type, gan_type, dim, slider, img):
12
 
13
+
14
  if not os.path.exists('temp'):
15
  os.system('mkdir temp')
16
 
 
51
  formatted = (output * 255.0 / np.max(output)).astype('uint8')
52
  out_im = Image.fromarray(formatted)
53
  out_im.save("Images/Input-Test/1_d.png", "PNG")
54
+
55
 
56
  c_images = '1'
57
  name_output = 'out'
 
63
  ])
64
  subprocess.run(["python", "WiggleResults/split.py", "--dim", dim])
65
 
66
+ path_video = os.path.join(os.path.dirname(__file__), 'WiggleResults' , name_output + '_0.mp4')
67
+ print(path_video)
68
+
69
+ return [img,f'WiggleResults/' + name_output + '_0.gif', path_video, f'WiggleResults/'+ name_output + '.jpg']
70
 
71
 
72
  with gr.Blocks() as demo:
 
87
  out = [gr.Image(type="pil", label="depth_estimation")]
88
  with gr.Row():
89
  out.append(gr.Image(type="file", label="Output_wiggle_gif"))
90
+ out.append(gr.Video(label="Output_wiggle_video"))
91
  out.append(gr.Image(type="file", label="Output_images"))
92
  btn = gr.Button("Calculate depth + Wiggle")
93
  btn.click(fn=calculate_depth, inputs=inp, outputs=out)