Python - Display 3D Point Cloud [closed]
Asked Answered
I

4

31

I have a .PLY file that contains a 3D Point Cloud: I want to plot it and visualize it in Python. The .PLY file contains ONLY vertex and NOT faces.

Could you indicate me a simple Python library that will take care of plotting the 3D Point Cloud?

It is important to remark that I am not interested in plotting a Mesh, but just the Point Cloud.

Inchmeal answered 21/6, 2018 at 9:58 Comment(0)
I
47

For anybody wondering for an easy way to read and display PLY point clouds in Python I answer my own question reporting what I've found to be the best solution in my case.

Open cmd and type:

pip install open3d

This will install Open3D on your machine and you will then be able to read and display your PLY point clouds just by executing the following sample script:

from open3d import *    

def main():
    cloud = io.read_point_cloud("output.ply") # Read point cloud
    visualization.draw_geometries([cloud])    # Visualize point cloud      

if __name__ == "__main__":
    main()
Inchmeal answered 7/9, 2018 at 16:0 Comment(7)
Some Linux users may need to install open3d using the command pip install open3d-pythonOkra
Anaconda users open anaconda-prompt and type: conda install -c open3d-admin open3dHauptmann
currently open3d still lacks lots of unilities as a point cloud viewerHazen
It does not work for me. "draw_geometries" does not existComedown
Also does not work for Apple M1Concentre
It should read now: cloud = io.read_point_cloud("cloud.ply")Visit
@Comedown @Concentre try using instead: visualization.draw_geometries([cloud])Visit
B
14

Try pptk (point processing toolkit). The package has a 3-d point cloud viewer that directly takes a 3-column numpy array as input, and is able to interactively visualize 10-100 million points. (It reduces the number of points that needs rendering in each frame by using an octree to cull points outside the view frustum and to approximate groups of far away points as single points)

To install,

>> pip install pptk

To visualize 100 randomly generated points in Python,

>> import pptk
>> import numpy as np
>> P = np.random.rand(100,3)
>> v = pptk.viewer(P)

screenshot of pptk viewer visualizing 100 random points

The documentation website also has a tutorial specifically on visualizing point clouds loaded from .ply files.

Bi answered 9/10, 2018 at 15:55 Comment(9)
I'm searching in the pptk documentation but am not able to find any utility that would let me dinamically add and remove PLY inside the same visualizer. Do you know if it's possible to do that? I'm trying to create a dynamic PLY visualizer: given N PLY files each one of them has to be shown in the visualizer, one after the otherInchmeal
@Inchmeal Assuming you have the PLY files loaded into a list called X, would something like this work: for x in X: v = pptk.viewer(x); v.wait(); v.close() ? Unforutnately, this opens each point cloud in a new viewer. To load a new point cloud in the same viewer, you'll need to use viewer.load, which currently seems to be buggy :(Bi
Does NOT install on MacOS 10.13.6, Python 3.7.2.Voorhis
call to pptk.viewer(P) never returns :-(Sackey
doesn't work for my on virtual boxEmporium
beautiful works like a charm !Ankylose
also have issues with it hanging after an apparently successful install through pipMatisse
@Bi I am curious to know if I can use pptk for down-sampling the number of points say from 400,000 points to 2000 points. I searched the existing documents but didn't find any link.Honeydew
not available in latest versions of pythonLionfish
C
7

You could use https://github.com/daavoo/pyntcloud to visualize the PLY inside a Jupyter notebook:

from pyntcloud import PyntCloud

human_face = PyntCloud.from_file("human_face.ply")

human_face.plot()
Celadon answered 25/6, 2018 at 11:11 Comment(1)
Could you share the PLY file??Celadon
S
0

You could use vtk which has python bindings to just display. Code snippet

If you want to process your data with numpy etc. I recommend the following steps:

  1. Convert .ply to .pcd (ascii) : pcl_ply2pcd input.ply output.pcd -format 0
  2. Use pypcd which is a python module for reading and writing .pcd files
  3. Pypcd returns a numpy ndarray which can be used perfectly with matplotlib

If you want to stay in the pcl world there is a python-pcl module containing bindings to the library.

I can elaborate further on any of these if one of these fits your needs.

Sewerage answered 21/6, 2018 at 11:37 Comment(2)
Hello, doing what you suggest results in the following error: "('Saving point cloud to', 'out.pcd') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "convertcloud/converter.py", line 74, in convert header = self._generate_header(extension) File "convertcloud/converter.py", line 102, in _generate_header header = header_gen.pcd() File "convertcloud/formats.py", line 401, in pcd typ += types[field.type] + " " KeyError: u'uchar'"Inchmeal
Could you clarify how to convert a PLY file with X,Y,Z - R,G,B information in the header, into the correspondant PCD file? Any help will be highly appreciated. Thank you in advanceInchmeal

© 2022 - 2024 — McMap. All rights reserved.