fffiloni commited on
Commit
53c7f91
·
1 Parent(s): a570d5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -30,13 +30,19 @@ import tempfile
30
  from pathlib import Path
31
  from urllib.request import urlretrieve
32
 
33
- def write_flo(filename, flow):
34
  """
35
- write optical flow in Middlebury .flo format
 
36
  :param flow: optical flow map
37
  :param filename: optical flow file path to be saved
38
  :return: None
 
 
 
39
  """
 
 
40
  f = open(filename, 'wb')
41
  magic = np.array([202021.25], dtype=np.float32)
42
  (height, width) = flow.shape[0:2]
@@ -46,7 +52,7 @@ def write_flo(filename, flow):
46
  w.tofile(f)
47
  h.tofile(f)
48
  flow.tofile(f)
49
- f.close()
50
 
51
 
52
  def infer():
@@ -141,7 +147,7 @@ def infer():
141
  flow_img = flow_to_image(predicted_flow).to("cpu")
142
  # output_folder = "/tmp/" # Update this to the folder of your choice
143
  write_jpeg(flow_img, f"predicted_flow.jpg")
144
- flo_file = write_flo("flofile.flo", predicted_flow).to("cpu")
145
  return "done", "predicted_flow.jpg", flo_file
146
  ####################################
147
  # Bonus: Creating GIFs of predicted flows
 
30
  from pathlib import Path
31
  from urllib.request import urlretrieve
32
 
33
+ def write_flo_file(flow, filename):
34
  """
35
+ Write optical flow in Middlebury .flo format
36
+
37
  :param flow: optical flow map
38
  :param filename: optical flow file path to be saved
39
  :return: None
40
+
41
+ from https://github.com/liruoteng/OpticalFlowToolkit/
42
+
43
  """
44
+ # forcing conversion to float32 precision
45
+ flow = flow.astype(np.float32)
46
  f = open(filename, 'wb')
47
  magic = np.array([202021.25], dtype=np.float32)
48
  (height, width) = flow.shape[0:2]
 
52
  w.tofile(f)
53
  h.tofile(f)
54
  flow.tofile(f)
55
+ f.close()
56
 
57
 
58
  def infer():
 
147
  flow_img = flow_to_image(predicted_flow).to("cpu")
148
  # output_folder = "/tmp/" # Update this to the folder of your choice
149
  write_jpeg(flow_img, f"predicted_flow.jpg")
150
+ flo_file = write_flo(predicted_flow, "flofile.flo").to("cpu")
151
  return "done", "predicted_flow.jpg", flo_file
152
  ####################################
153
  # Bonus: Creating GIFs of predicted flows