Update app.py
Browse files
app.py
CHANGED
@@ -63,11 +63,31 @@ def warp_flow(img, flow):
|
|
63 |
res = cv2.remap(img, flow, None, cv2.INTER_LINEAR)
|
64 |
return res
|
65 |
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
def warp(frame1, frame2, flo_path, blend=0.5, weights_path=None):
|
69 |
#flo_path = flo_path.cpu().data.numpy()
|
70 |
-
flow21 =
|
71 |
frame1pil = np.array(frame1.convert('RGB').resize((flow21.shape[1],flow21.shape[0])))
|
72 |
frame1_warped21 = warp_flow(frame1pil, flow21)
|
73 |
# frame2pil = frame1pil
|
|
|
63 |
res = cv2.remap(img, flow, None, cv2.INTER_LINEAR)
|
64 |
return res
|
65 |
|
66 |
+
def read_flo_file(filename):
|
67 |
+
"""
|
68 |
+
Read from Middlebury .flo file
|
69 |
+
:param flow_file: name of the flow file
|
70 |
+
:return: optical flow data in matrix
|
71 |
+
"""
|
72 |
+
f = open(filename, 'rb')
|
73 |
+
magic = np.fromfile(f, np.float32, count=1)
|
74 |
+
data2d = None
|
75 |
+
|
76 |
+
if 202021.25 != magic:
|
77 |
+
print('Magic number incorrect. Invalid .flo file')
|
78 |
+
else:
|
79 |
+
w = np.fromfile(f, np.int32, count=1)
|
80 |
+
h = np.fromfile(f, np.int32, count=1)
|
81 |
+
print("Reading %d x %d flow file in .flo format" % (h, w))
|
82 |
+
data2d = np.fromfile(f, np.float32, count=2 * w * h)
|
83 |
+
# reshape data into 3D array (columns, rows, channels)
|
84 |
+
data2d = np.resize(data2d, (h[0], w[0], 2))
|
85 |
+
f.close()
|
86 |
+
return data2d
|
87 |
|
88 |
def warp(frame1, frame2, flo_path, blend=0.5, weights_path=None):
|
89 |
#flo_path = flo_path.cpu().data.numpy()
|
90 |
+
flow21 = read_flo_file(flo_path)
|
91 |
frame1pil = np.array(frame1.convert('RGB').resize((flow21.shape[1],flow21.shape[0])))
|
92 |
frame1_warped21 = warp_flow(frame1pil, flow21)
|
93 |
# frame2pil = frame1pil
|