def flow_write_png(u,v,fpath,valid=None):
"""
Write KITTI optical flow.
"""
if not has_png:
print('Error. Please install the PyPNG library')
return
if valid==None:
valid_ = np.ones(u.shape,dtype='uint16')
else:
valid_ = valid.astype('uint16')
u_ = ((u*64.0)+2**15).astype('uint16')
v_ = ((v*64.0)+2**15).astype('uint16')
I = np.dstack((u_,v_,valid_))
W = png.Writer(width=u.shape[1],
height=u.shape[0],
bitdepth=16,
planes=3)
with open(fpath,'wb') as fil:
W.write(fil,I.reshape((-1,3*u.shape[1])))
评论列表
文章目录