Update app.py
Browse files
app.py
CHANGED
@@ -177,5 +177,28 @@ def infer():
|
|
177 |
#
|
178 |
# ffmpeg -f image2 -framerate 30 -i predicted_flow_%d.jpg -loop -1 flow.gif
|
179 |
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
gr.Interface(fn=infer, inputs=[], outputs=[gr.Textbox(), gr.Image(), gr.Files()]).launch()
|
|
|
177 |
#
|
178 |
# ffmpeg -f image2 -framerate 30 -i predicted_flow_%d.jpg -loop -1 flow.gif
|
179 |
|
180 |
+
def warp_flow(img, flow):
|
181 |
+
h, w = flow.shape[:2]
|
182 |
+
flow = flow.copy()
|
183 |
+
flow[:, :, 0] += np.arange(w)
|
184 |
+
flow[:, :, 1] += np.arange(h)[:, np.newaxis]
|
185 |
+
res = cv2.remap(img, flow, None, cv2.INTER_LINEAR)
|
186 |
+
return res
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
def warp(frame1, frame2, flo_path, blend=0.5, weights_path=None):
|
191 |
+
flow21 = np.load(flo_path)
|
192 |
+
frame1pil = np.array(frame1.convert('RGB').resize((flow21.shape[1],flow21.shape[0])))
|
193 |
+
frame1_warped21 = warp_flow(frame1pil, flow21)
|
194 |
+
# frame2pil = frame1pil
|
195 |
+
frame2pil = np.array(frame2.convert('RGB').resize((flow21.shape[1],flow21.shape[0])))
|
196 |
+
|
197 |
+
if weights_path:
|
198 |
+
forward_weights = load_cc(weights_path)
|
199 |
+
blended_w = frame2pil*(1-blend) + blend*(frame1_warped21*forward_weights+frame2pil*(1-forward_weights))
|
200 |
+
else: blended_w = frame2pil*(1-blend) + frame1_warped21*(blend)
|
201 |
+
|
202 |
+
return PIL.Image.fromarray(blended_w.astype('uint8'))
|
203 |
+
|
204 |
gr.Interface(fn=infer, inputs=[], outputs=[gr.Textbox(), gr.Image(), gr.Files()]).launch()
|