mihaidusmanu / d2-net

D2-Net: A Trainable CNN for Joint Description and Detection of Local Features
Other
761 stars 163 forks source link

MegaDepth saved npz poses as 1x4 array but should be 4x4 #92

Closed MACILLAS closed 1 year ago

MACILLAS commented 2 years ago

Hi @mihaidusmanu,

I'm a little bit confused about the saved poses in d2-net/megadepth_utils/preprocess_scene.py

From line 177-187 you append the current_pose to poses

    # World-to-Camera pose
    current_pose = np.zeros([4, 4])
    current_pose[: 3, : 3] = R
    current_pose[: 3, 3] = t
    current_pose[3, 3] = 1
    # Camera-to-World pose
    # pose = np.zeros([4, 4])
    # pose[: 3, : 3] = np.transpose(R)
    # pose[: 3, 3] = -np.matmul(np.transpose(R), t)
    # pose[3, 3] = 1
    poses.append(current_pose)

Here poses should be a list of 4x4 arrays...

But when I do np.load scene_info/0000.npz and refer to the pose I get a size 4 vector. I cross referenced this array with COLMAP sparse_text and found that these are not the quaternions rather [ x, x, x, Tx] which leads to me believe that the size 4 pose vector is the first row of the 4x4 current_pose...

I'm loading the npz file with the following

np.load(os.path.join(d2net_scene_info_dir, '0000.npz'), allow_pickle=True)

Could you please advise? Is the pose not being used in your method or something?

Kind Regards,

MACILLAS commented 2 years ago

For example:

COLMAP sparse-txt Image list with two lines of data per image: IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME POINTS2D[] as (X, Y, POINT3D_ID) 8301 0.996887 0.0715785 0.0326907 0.00488557 -0.749445 -3.9046 -1.52595 8301 3409963756_f34ab1229a_o.jpg

Loaded from Scene_Info NPZ imgdir ==> Undistorted_SfM/0000/images/3409963756_f34ab1229a_o.jpg pose ==> [ 0.9978149 -0.00506082 0.06587729 -0.749445 ]

mihaidusmanu commented 2 years ago

The training pipeline is using the camera poses to warp from an image to another. Where did you obtain the 0000.npz file that only has 1x4 array pose? Could you share this file with me? Maybe a recent update of numpy broke something.

MACILLAS commented 2 years ago

Okay that makes sense, thanks for the clarification! :) The LOFTR repo, which refers to your method for preprocessing MegaDepth also has this issue...

I got it from your Google Drive for the processed npz files.

Thanks Again.

mihaidusmanu commented 2 years ago

I don't have any issues with the npz files from the Drive:

import numpy as np
f = np.load('0000.0.npz', allow_pickle=True)
print(f['poses'][1])

prints

[[ 0.9978149  -0.00506082  0.06587729 -0.749445  ]
 [ 0.01442063  0.9897053  -0.14239197 -3.9046    ]
 [-0.06447848  0.14303082  0.98761567 -1.52595   ]
 [ 0.          0.          0.          1.        ]]

I am using numpy 1.22.0.