Python interface

If Open3D is successfully compiled with Python binding, it will create a Python library with name py3d. Typically, you will find a file py3d.so in build/lib directory. This tutorial shows how to import py3d module and print out help information. For trouble shooing, see Python binding.

# src/Python/Tutorial/Basic/python_binding.py

import numpy as np

def example_help_function():
    import py3d as py3d
    help(py3d)
    help(py3d.PointCloud)
    help(py3d.read_point_cloud)

def example_import_function():
    from py3d import read_point_cloud
    pcd = read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")
    print(pcd)

if __name__ == "__main__":
    example_help_function()
    example_import_function()

This scripts has two functions: example_help_function and example_import_all that show very basic usage of Open3D Python module.

Note

Depending on environment, the name of Python library may not py3d.so. Regardless of the file name, import py3d should work.

Import py3d module

def example_import_function():
    from py3d import read_point_cloud
    pcd = read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")
    print(pcd)

This imports read_point_cloud function from py3d module. It reads a point cloud file and returns an instance of PointCloud class. print(pcd) prints brief information of the point cloud:

PointCloud with 198835 points.

Using built-in help function

It is recommended to use Python built-in help function to get definitions and instructions of Open3D functions and classes. For example,

def example_help_function():
    import py3d as py3d
    help(py3d)
    help(py3d.PointCloud)
    help(py3d.read_point_cloud)

Browse py3d

help(py3d) prints documents of py3d module.

Help on module py3d:

NAME
    py3d - Python binding of Open3D

FILE
    /Users/myaccount/Open3D/build/lib/py3d.so

CLASSES
    __builtin__.object
        CorrespondenceChecker
            CorrespondenceCheckerBasedOnDistance
            CorrespondenceCheckerBasedOnEdgeLength
            CorrespondenceCheckerBasedOnNormal
        DoubleVector
        Feature
        Geometry
            Geometry2D
                Image
            Geometry3D
                PointCloud
                TriangleMesh
:

Description of a class in py3d

help(py3d.PointCloud) provides description of PointCloud class.

Help on class PointCloud in module py3d:

class PointCloud(Geometry3D)
 |  Method resolution order:
 |      PointCloud
 |      Geometry3D
 |      Geometry
 |      __builtin__.object
 |
 |  Methods defined here:
 |
 |  __add__(...)
 |      __add__(self: py3d.PointCloud, arg0: py3d.PointCloud) -> py3d.PointCloud
 |
:

Description of a function in py3d

help(py3d.read_point_cloud) provides description of input argument and return type of read_point_cloud function.

Help on built-in function read_point_cloud in module py3d:

read_point_cloud(...)
    read_point_cloud(filename: unicode) -> py3d.PointCloud

    Function to read PointCloud from file