(filename,uv,v=None)
Write optical flow to file.
    
    If v is None, uv is assumed to contain both u and v channels,
    stacked in depth.
    Original code by Deqing Sun, adapted from Daniel Scharstein.
Write optical flow to file.
    
    If v is None, uv is assumed to contain both u and v channels,
    stacked in depth.
    Original code by Deqing Sun, adapted from Daniel Scharstein.
Write optical flow to file . If v is None uv is assumed to contain both u and v channels stacked in depth . Original code by Deqing Sun adapted from Daniel Scharstein .
def writeFlow(filename,uv,v=None):
    """ Write optical flow to file.
    
    If v is None, uv is assumed to contain both u and v channels,
    stacked in depth.
    Original code by Deqing Sun, adapted from Daniel Scharstein.
    """
    nBands = 2

    if v is None:
        assert(uv.ndim == 3)
        assert(uv.shape[2] == 2)
        u = uv[:,:,0]
        v = uv[:,:,1]
    else:
        u = uv

    assert(u.shape == v.shape)
    height,width = u.shape
    f = open(filename,'wb')
    # write the header
    f.write(TAG_CHAR)
    np.array(width).astype(np.int32).tofile(f)
    np.array(height).astype(np.int32).tofile(f)
    # arrange into matrix form
    tmp = np.zeros((height, width*nBands))
    tmp[:,np.arange(width)*2] = u
    tmp[:,np.arange(width)*2 + 1] = v
    tmp.astype(np.float32).tofile(f)
    f.close()
def writeFlow ( filename , uv , v = None ) : nBands = 2 if v is None : assert ( uv . ndim == 3 ) assert ( uv . shape [ 2 ] == 2 ) u = uv [ : , : , 0 ] v = uv [ : , : , 1 ] else : u = uv assert ( u . shape == v . shape ) height , width = u . shape f = open ( filename , 'wb' ) # write the header f . write ( TAG_CHAR ) np . array ( width ) . astype ( np . int32 ) . tofile ( f ) np . array ( height ) . astype ( np . int32 ) . tofile ( f ) # arrange into matrix form tmp = np . zeros ( ( height , width * nBands ) ) tmp [ : , np . arange ( width ) * 2 ] = u tmp [ : , np . arange ( width ) * 2 + 1 ] = v tmp . astype ( np . float32 ) . tofile ( f ) f . close ( )