cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.12k stars 579 forks source link

Point Cloud Registration #374

Open Martines1 opened 7 months ago

Martines1 commented 7 months ago

Hi, I have a point cloud of 10 frames in ply format and png images from a 3D camera at different angles without calibration pattern, thus my point clouds are not in the common space. I have tried your method to merge point clouds; however, it's missing a lot of pixels (data points) comparing the points3D bin file with my original point cloud. I have also created a transformation matrix from image quaternions and positions and then transformed my original point cloud, but it does not align the original point clouds at all.  Have I done something wrong, or is it not possible to align the original point cloud with the output values (cameras.bin, images.bin, points3D.bin)?

Code to get transformation matrix as numpy array:

from hloc.utils.read_write_model import read_model
import numpy as np
from scipy.spatial.transform import Rotation as R

cameras, images, points3D = read_model("outputs/demo/sfm/", ext='.bin')

ids = list(images.keys())
for i in range(len(ids)):
    quat = np.array(list(images[ids[i]].qvec))
    R_mat = R.from_quat(quat).as_matrix()
    pos = np.array(list(images[ids[i]].tvec))
    T_mat = np.eye(4)
    T_mat[:3, :3] = R_mat
    T_mat[:3,3] = pos
    np.save(f'transformation_matrix{i}', T_mat)