freealise commited on
Commit
0c11dd2
·
verified ·
1 Parent(s): 25626e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -88,7 +88,7 @@ def get_frames(video_in, step, name, resize_w):
88
  def create_video(frames, fps, type):
89
  print("building video result")
90
  clip = ImageSequenceClip(frames, fps=fps)
91
- clip.write_videofile(type + "_result.mp4", fps=fps)
92
 
93
  return type + "_result.mp4"
94
 
@@ -165,9 +165,15 @@ def infer(url_in,interpolation,fps_output,resize_n,winsize,o_flow):
165
  alpha = 1.0/len(result_frames)
166
  beta = (1.0 - alpha)
167
  res = cv2.addWeighted(rgb, alpha, res, beta, 0.0, res)
168
- rgb = cv2.cvtColor(rgb, cv2.COLOR_GRAY2RGB)
169
- cv2.imwrite(f"opticalfb{i}.jpg", rgb)
170
- depth_frames.append(f"opticalfb{i}.jpg")
 
 
 
 
 
 
171
  i+=1
172
  prvs = nxt
173
 
@@ -222,7 +228,7 @@ with gr.Blocks() as demo:
222
  video_input = gr.Video()
223
  video_input.change(fn=loadurl, inputs=[video_input], outputs=[url_input])
224
  resize_num = gr.Slider(minimum=1, maximum=4096, step=1, value=256, label="Resize to width: ")
225
- of_check = gr.Checkbox(value=True, label="Detect motion for depth map: ")
226
  winsize_num = gr.Slider(minimum=1, maximum=256, step=1, value=15, label="Motion detection window size: ")
227
  with gr.Row():
228
  interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")
 
88
  def create_video(frames, fps, type):
89
  print("building video result")
90
  clip = ImageSequenceClip(frames, fps=fps)
91
+ clip.write_videofile(type + "_result.mp4", fps=fps, codec='libx265', ffmpeg_params=['-c:v', 'libx265'], audio = False)
92
 
93
  return type + "_result.mp4"
94
 
 
165
  alpha = 1.0/len(result_frames)
166
  beta = (1.0 - alpha)
167
  res = cv2.addWeighted(rgb, alpha, res, beta, 0.0, res)
168
+ rgb = cv2.cvtColor(rgb, cv2.COLOR_GRAY2RGBA)
169
+
170
+ lo = np.array([0,0,0,0])
171
+ hi = np.array([0,0,0,255])
172
+ mask = cv2.inRange(rgb, lo, hi)
173
+ rgb[mask>0] = (0,0,0,0)
174
+
175
+ cv2.imwrite(f"opticalfb{i}.png", rgb)
176
+ depth_frames.append(f"opticalfb{i}.png")
177
  i+=1
178
  prvs = nxt
179
 
 
228
  video_input = gr.Video()
229
  video_input.change(fn=loadurl, inputs=[video_input], outputs=[url_input])
230
  resize_num = gr.Slider(minimum=1, maximum=4096, step=1, value=256, label="Resize to width: ")
231
+ of_check = gr.Checkbox(value=True, label="Detect motion to remove background: ")
232
  winsize_num = gr.Slider(minimum=1, maximum=256, step=1, value=15, label="Motion detection window size: ")
233
  with gr.Row():
234
  interpolation_slider = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Interpolation Steps: ")