facebookresearch / vggsfm

VGGSfM: Visual Geometry Grounded Deep Structure From Motion
Other
819 stars 47 forks source link

Color Value Not Saved When Saving Reconstructed Points3D with Pycolmap #32

Closed hwanhuh closed 1 month ago

hwanhuh commented 1 month ago

First of all, thank you for conducting and publishing this great study.

I've encountered a small error: the color value is not saved when saving reconstructed points3D with pycolmap. This problem can be resolved by using plyfile to save points3D.ply as shown below.

Solution:

  1. Define a function to save the PLY file:
from plyfile import PlyData, PlyElement
import numpy as np

def storePly(path, xyz, rgb):
    dtype = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'),
             ('nx', 'f4'), ('ny', 'f4'), ('nz', 'f4'),
             ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]

    normals = np.zeros_like(xyz)

    elements = np.empty(xyz.shape[0], dtype=dtype)
    attributes = np.concatenate((xyz, normals, rgb), axis=1)
    elements[:] = list(map(tuple, attributes))

    vertex_element = PlyElement.describe(elements, 'vertex')
    ply_data = PlyData([vertex_element])
    ply_data.write(path)
  1. Use the storePly function in demo.py at line 150:
storePly(os.path.join(output_path, "points3D.ply"), predictions["points3D"].clone().cpu().numpy(), predictions["points3D_rgb"].clone().cpu().numpy() * 255)
jytime commented 1 month ago

Thanks for pointing out this! I will check if we can easily save the colors to pycolmap reconstruction file. If not, we can store the rgb files to a separate file as you suggested.

jytime commented 1 month ago

Hi,

I made a quick fix (as shown in https://github.com/facebookresearch/vggsfm/commit/25ec3e83c6a53b14cc86a77dee8fcc7267d158b3 and b15f0d86bcd654067ff7a1d00b0cb74574ee83a6) to save the point rgb color to colmap reconstruction object. Please feel free to let me know if it does not work for you.