Ejemplo n.º 1
0
def test_flow2rgb():
    flow = np.array([[[0, 0], [0.5, 0.5], [1, 1], [2, 1], [3, np.inf]]],
                    dtype=np.float32)
    flow_img = mmcv.flow2rgb(flow)
    # yapf: disable
    assert_array_almost_equal(
        flow_img,
        np.array([[[1., 1., 1.],
                   [1., 0.826074731, 0.683772236],
                   [1., 0.652149462, 0.367544472],
                   [1., 0.265650552, 5.96046448e-08],
                   [0., 0., 0.]]],
                 dtype=np.float32))
Ejemplo n.º 2
0
                numpy.array(PIL.Image.open(img_second))[:, :, ::-1].transpose(
                    2, 0, 1).astype(numpy.float32) * (1.0 / 255.0))
            tensorOutput = estimate(tensorFirst, tensorSecond)
            print(arguments_strFolOut, directory_name)
            outfile = os.path.join(arguments_strFolOut, '%06d.flo' % (i))
            objectOutput = open(outfile, 'wb')
            numpy.array([80, 73, 69, 72], numpy.uint8).tofile(objectOutput)
            numpy.array([tensorOutput.size(2),
                         tensorOutput.size(1)],
                        numpy.int32).tofile(objectOutput)
            numpy.array(tensorOutput.numpy().transpose(1, 2, 0),
                        numpy.float32).tofile(objectOutput)
            objectOutput.close()

            if arguments_strVisFlow:
                flow = mmcv.flow2rgb(mmcv.flowread(outfile))
                io.imsave(outfile[0:-3] + 'png', flow)

    else:

        tensorFirst = torch.FloatTensor(
            numpy.array(
                PIL.Image.open(arguments_strFirst))[:, :, ::-1].transpose(
                    2, 0, 1).astype(numpy.float32) * (1.0 / 255.0))
        tensorSecond = torch.FloatTensor(
            numpy.array(
                PIL.Image.open(arguments_strSecond))[:, :, ::-1].transpose(
                    2, 0, 1).astype(numpy.float32) * (1.0 / 255.0))
        tensorOutput = estimate(tensorFirst, tensorSecond)
        objectOutput = open(arguments_strOut, 'wb')