fffiloni commited on
Commit
54b38be
·
1 Parent(s): 428c2fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -35
app.py CHANGED
@@ -60,41 +60,10 @@ def write_flo(flow, filename):
60
 
61
  #warp using scipy
62
  def warp_image(im, flow):
63
- """
64
- Use optical flow to warp image to the next
65
- :param im: image to warp
66
- :param flow: optical flow
67
- :return: warped image
68
- """
69
- from scipy import interpolate
70
- image_height = im.shape[0]
71
- image_width = im.shape[1]
72
- flow_height = flow.shape[0]
73
- flow_width = flow.shape[1]
74
- n = image_height * image_width
75
- (iy, ix) = np.mgrid[0:image_height, 0:image_width]
76
- (fy, fx) = np.mgrid[0:flow_height, 0:flow_width]
77
- fx = fx.astype(np.float64)
78
- fy = fy.astype(np.float64)
79
- fx += flow[:,:,0]
80
- fy += flow[:,:,1]
81
- mask = np.logical_or(fx <0 , fx > flow_width)
82
- mask = np.logical_or(mask, fy < 0)
83
- mask = np.logical_or(mask, fy > flow_height)
84
- fx = np.minimum(np.maximum(fx, 0), flow_width)
85
- fy = np.minimum(np.maximum(fy, 0), flow_height)
86
- points = np.concatenate((ix.reshape(n,1), iy.reshape(n,1)), axis=1)
87
- xi = np.concatenate((fx.reshape(n, 1), fy.reshape(n,1)), axis=1)
88
- warp = np.zeros((image_height, image_width, im.shape[2]))
89
- for i in range(im.shape[2]):
90
- channel = im[:, :, i]
91
- values = channel.reshape(n, 1)
92
- new_channel = interpolate.griddata(points, values, xi, method='cubic')
93
- new_channel = np.reshape(new_channel, [flow_height, flow_width])
94
- new_channel[mask] = 1
95
- warp[:, :, i] = new_channel.astype(np.uint8)
96
-
97
- return warp.astype(np.uint8)
98
 
99
  def infer():
100
  video_url = "https://download.pytorch.org/tutorial/pexelscom_pavel_danilyuk_basketball_hd.mp4"
 
60
 
61
  #warp using scipy
62
  def warp_image(im, flow):
63
+ h, w = flow.shape[:2]
64
+ flow[:,:,0] += np.arange(w)
65
+ flow[:,:,1] += np.arange(h)[:,np.newaxis]
66
+ prevImg = cv2.remap(curImg, flow, None, cv.INTER_LINEAR)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  def infer():
69
  video_url = "https://download.pytorch.org/tutorial/pexelscom_pavel_danilyuk_basketball_hd.mp4"