mapillary / OpenSfM

Open source Structure-from-Motion pipeline
https://www.opensfm.org/
BSD 2-Clause "Simplified" License
3.35k stars 851 forks source link

Generated Point Cloud has no colors #741

Open cdapo opened 3 years ago

cdapo commented 3 years ago

Hi everyone, when generating a merged.ply file and open it with

import open3d as o3d
pcd = o3d.io.read_point_cloud('merged.ply')
print(pcd.colors)

it gives me

std::vector<Eigen::Vector3d> with 0 elements.
Use numpy.asarray() to access data.

Am I doing something wrong or does the point cloud come without colors?

fabianschenk commented 3 years ago

Hi @cdapo ,

A bit more information would be great. Could you post a code snippet or at least what dataset you're using. How does the point cloud look in Meshlab?

Our point cloud definitely comes with colors but open3d is not developed by us and I don't know what this library expects internally. As a first test, try to run opensfm_run_all in opensfm/bin with the berlin dataset. This generates a merged.ply in the undistorted folder and you can open it in Meshlab. This should look something like this: image

Good luck, Fabian

digvijayad commented 2 years ago

@fabianschenk

According to issue here

This reason for not reading colors is that OpenSfM generates the merged.ply file with diffuse_ headers for colors.

property uchar diffuse_red
property uchar diffuse_green
property uchar diffuse_blue

These are user-defined headers that are currently not supported by open3D.

The solution is to edit the OpenSfM/opensfm/io.py file and remove the diffuse_ from the properties in the function point_cloud_to_ply.

def point_cloud_to_ply(
    points: np.ndarray,
    normals: np.ndarray,
    colors: np.ndarray,
    labels: np.ndarray,
    fp: TextIO,
) -> None:
    fp.write("ply\n")
    ...
    ...
    fp.write("property uchar red\n")       # Changed from diffuse_red
    fp.write("property uchar green\n")     # Changed from diffuse_green
    fp.write("property uchar blue\n")      # Changed from diffuse_blue
    fp.write("property uchar class\n")
    fp.write("end_header\n")

The colors should be read correctly now.

fabianschenk commented 2 years ago

Hi @digvijayad ,

Thanks for investigating this. Could you create a PR?

Best, Fabian

digvijayad commented 2 years ago

@fabianschenk Yes I'll create one.

digvijayad commented 2 years ago

@fabianschenk I have created the PR.

digvijayad commented 2 years ago

According to here: http://gamma.cs.unc.edu/POWERPLANT/papers/ply.pdf and here: http://paulbourke.net/dataformats/ply/ The red, green, and blue are the standard ply headers, whereas diffuse_red, ambient_red, or specular red are user-defined elements.

Also worth noting is that the old ply, with 'diffuse' prefix, when exported through MeshLab generates headers without 'diffuse' prefix.

On Wed, 13 Jul 2022 at 19:34, Piero Toffanin @.***> wrote:

Worth noting that this is probably an issue with open3d and not with OpenSfM per-se, PLY doesn't really have a "standard" and the current PLY outputs from OpenSfM are just fine (as shown by the ability of Meshlab to open them).

— Reply to this email directly, view it on GitHub https://github.com/mapillary/OpenSfM/issues/741#issuecomment-1183549813, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWZR25DVMMDX6DDCOKV2O3VT4D3XANCNFSM44AZYJ5Q . You are receiving this because you were mentioned.Message ID: @.***>