def rotate_ground(original, theta, horizon=60, half_height=360 / 2, focal=1.0):
height, width, channel = original.shape
# the target grids
yp = range(height - horizon, height)
xp = range(0, width)
# from pixel to coordinates
y0 = (np.array(yp) - half_height) * 1.0 / half_height
x0 = (np.array(xp) - width / 2) / (width / 2.0)
# form the mesh
mesh = MyDataset.generate_meshlist(x0, y0)
# compute the source coordinates
st = math.sin(theta)
ct = math.cos(theta)
deno = ct * focal + st * mesh[:, 0]
out = np.array([(-st * focal + ct * mesh[:, 0]) / deno, mesh[:, 1] / deno])
# interpolate
vout = []
for i in range(3):
f = interpolate.RectBivariateSpline(y0, x0, original[- horizon:, :, i])
values = f(out[1, :], out[0, :], grid=False)
vout.append(values)
lower = np.reshape(vout, (3, width, horizon)).transpose((2, 1, 0)).astype("uint8")
# compute the upper part
out = np.reshape(out[0, :], (width, horizon))
out = out[:, 0]
f = interpolate.interp1d(x0, original[:-horizon, :, :], axis=1,
fill_value=(original[:-horizon, 0, :], original[:-horizon, -1, :]),
bounds_error=False)
ans = f(out)
ans = ans.astype("uint8")
return np.concatenate((ans, lower), axis=0)
评论列表
文章目录