OpenSfM icon indicating copy to clipboard operation
OpenSfM copied to clipboard

Generated Point Cloud has no colors

Open cdapo opened this issue 3 years ago • 6 comments

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?

cdapo avatar May 03 '21 13:05 cdapo

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

fabianschenk avatar May 03 '21 15:05 fabianschenk

@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.

digvijayad avatar Jul 06 '22 17:07 digvijayad

Hi @digvijayad ,

Thanks for investigating this. Could you create a PR?

Best, Fabian

fabianschenk avatar Jul 07 '22 07:07 fabianschenk

@fabianschenk Yes I'll create one.

digvijayad avatar Jul 13 '22 09:07 digvijayad

@fabianschenk I have created the PR.

digvijayad avatar Jul 13 '22 10:07 digvijayad

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: @.***>

digvijayad avatar Jul 14 '22 01:07 digvijayad