29

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.

Employee
  • 3,109
  • 5
  • 31
  • 50

4 Answers4

42

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()
Employee
  • 3,109
  • 5
  • 31
  • 50
16

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.

victoriousluser
  • 161
  • 1
  • 4
  • 2
    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 other – Employee Oct 10 '18 at 09:03
  • 3
    @Employee 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 :( – victoriousluser Oct 12 '18 at 22:10
  • 3
    Does NOT install on MacOS 10.13.6, Python 3.7.2. – Ray Feb 28 '19 at 11:09
  • 7
    call to pptk.viewer(P) never returns :-( – user1953366 Oct 31 '19 at 15:15
  • doesn't work for my on virtual box – TripleS Dec 04 '19 at 07:15
  • beautiful works like a charm ! – r4bb1t Feb 28 '20 at 04:12
  • also have issues with it hanging after an apparently successful install through pip – ldog Mar 02 '20 at 00:38
  • @victoriousluser 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. – user1410665 Dec 03 '20 at 17:07
  • not available in latest versions of python – Lloyd Rayner Mar 24 '21 at 21:19
6

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()
David de la Iglesia
  • 2,436
  • 14
  • 29
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.

Danipol
  • 79
  • 1
  • 5
  • Hello, doing what you suggest results in the following error: "('Saving point cloud to', 'out.pcd') Traceback (most recent call last): File "", line 1, in 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'" – Employee Jun 28 '18 at 11:34
  • 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 advance – Employee Jun 28 '18 at 12:19