Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I read and use optical flow from '.npz' files? #62

Open
MiaoJieF opened this issue Jul 28, 2023 · 2 comments
Open

How should I read and use optical flow from '.npz' files? #62

MiaoJieF opened this issue Jul 28, 2023 · 2 comments

Comments

@MiaoJieF
Copy link

MiaoJieF commented Jul 28, 2023

Here's my code. I am trying to read the optical flow to warp frame 2 back to frame 1. But the results appear to be wrong.

        flo = np.load(r'E:\Dataset\SHIFT\flow\0003-17fb\00000040_flow_front.npz')
        flo = flo['flow']
        img_1 = cv2.imread('video/00000040.jpg')
        img_2 = cv2.imread('video/00000041.jpg')

        flow_vis = flow_viz.flow_to_image(flo)
        cv2.imshow('flow_vis', flow_vis)
        cv2.imshow('img', img_1)
        cv2.imshow('img2', img_2)

        img_ten = torch.tensor(img_2).unsqueeze(dim=0).permute(0, 3, 1, 2).cuda().float()
        flow = torch.tensor(flo).unsqueeze(dim=0).permute(0, 3, 1, 2).cuda() * 1280

        img_ten_warp = warp(img_ten, flow)
        img_ten_warp = img_ten_warp.squeeze(dim=0).permute(1, 2, 0).cpu().numpy().astype(np.uint8)

        cv2.imshow('img_ten_warp', img_ten_warp)
        cv2.waitKey()

image

@suniique
Copy link
Collaborator

Hey @MiaoJieF, thanks for the question!
It seems that in your code, you didn't map the optical flow range correctly. In the Carla simulator, the optical flow range is in [-2, 2] (you cloud check its official document https://carla.readthedocs.io/en/latest/ref_sensors/#optical-flow-camera). Also, the codes in carla-simulator/carla#4795 might be helpful.
Please come back to me if the problem persists!

@MiaoJieF
Copy link
Author

MiaoJieF commented Jul 29, 2023

Hey @MiaoJieF, thanks for the question! It seems that in your code, you didn't map the optical flow range correctly. In the Carla simulator, the optical flow range is in [-2, 2] (you cloud check its official document https://carla.readthedocs.io/en/latest/ref_sensors/#optical-flow-camera). Also, the codes in carla-simulator/carla#4795 might be helpful. Please come back to me if the problem persists!

Thank you for your reply. I still have a little doubt, is the optical flow provided in SHIFT from t->t-1 or t->t+1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants