Open3d学习计划——2(使用帮助与IO)

Open3d学习计划——2

上篇文章,我们介绍了Open3D是什么,和Python版本的如何安装。本篇文章将介绍原文档中Open3D得基础用法,本文翻译文档为0.10.0版本open3d文档,更多之前版本的信息请去查阅官方文档,不同版本API会有少许不同,请注意(如果在使用中提示没有某个类或者函数,就去上篇文章找到官方文档接口,去看看是不是函数发生了变化)。

Python接口

本节将会介绍如何导入open3d包并打印帮助信息。通过下面的代码就可以导入open3d

import open3d as o3d   #导入open3d
pcd = 03d.io.read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")
print(pcd)
##打印: geometry::PointCloud with 198835 points.

这里是从open3d模块中导入read_point_cloud函数,该函数可以读取点云文件并返回一个Pointcloud实例。print(pcd)可以打印点云的简略信息。

使用内置的帮助功能

help(o3d)可以打印open3d模块文件

help(03d)
Help on package open3d:

NAME
    open3d
    
PACKAGE CONTENTS
    core
    j_visualizer
    open3d_pybind
SUBMODULES
    camera
    color_map
    cuda
    geometry
    integration
    io
    odometry
    registration
    utility
    visualization
DATA
    none = <open3d.open3d_pybind.NoneType object>
VERSION
    0.10.0.0
FILE
    /home/yixing/miniconda3/envs/open3d3/lib/python3.6/site-packages/open3d/__init__.py

打印open3d中某个类的描述

help(open3d.PointCloud)可以用来打印PointCloud类的描述。

help(o3d.geometry.PointCloud)

因为描述太长就不在这里粘贴出来,感兴趣的请自己尝试

打印open3d中某个函数的描述

help(open3d.io.read_point_cloud)提供了read_point_cloud函数的描述,主要包括输入参数和返回类型。

help(o3d.io.read_point_cloud)
Help on built-in function read_point_cloud in module open3d.open3d_pybind.io:

read_point_cloud(...) method of builtins.PyCapsule instance
    read_point_cloud(filename, format='auto', remove_nan_points=True, remove_infinite_points=True, print_progress=False)

    Function to read PointCloud from file

    Args:
        filename (str): Path to file.
        format (str, optional, default='auto'): The format of the input file. When not specified or set as ``auto``, the format is inferred from file extension name.
        remove_nan_points (bool, optional, default=True): If true, all points that include a NaN are removed from the PointCloud.
        remove_infinite_points (bool, optional, default=True): If true, all points that include an infinite value are removed from the PointCloud.
        print_progress (bool, optional, default=False): If set to true a progress bar is visualized in the console

    Returns:
        open3d.geometry.PointCloud

文件IO

这一节将会介绍基本几何图形的读取和写入

点云(Point Cloud)

通过下面的代码读写点云

print("Testing IO for point cloud ...")
pcd = o3d.io.read_point_cloud("../../TestData/fragment.pcd")
print(pcd)
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)

>>>>Testing IO for point cloud ...
>>>>geometry::PointCloud with 113662 points.

print()能用来显示点云的摘要.
open3d可以通过文件扩展名自动推断文件类型,下面是支持的点云文件类型。

FormatDescription
xyz每一行包括 [x,y,z] 三个值,x,y,z 是三维坐标
xyzn每一行包括 [x,y,z,nx,ny,nz] 六个值,其中nx,ny,nz 是法线
xyzrgb每一行包括 [x,y,z,r,g,b] 六个值,这里r,g,b的范围在[0,1]浮动
pts第一行是一个整数,表示点的个数。之后每一行包括 [x,y,z,i,r,g,b] 七个值,其中rgb的类型为uint8
ply这个格式可以包含点云和网格数据,详情请参考这个链接
pcd请看官方给出的php文件,链接
也可以显示的指定文件类型,这样将会忽略文件扩展名。
pcd =o3d.io.read_point_cloud("../../my_points.txt",format='xyz')

网格(Mesh)

通过以下代码可以读写网格数据。

print("Testing IO for meshes ...")
mesh = 03d.io.read_triangle_mesh("../../TestData/knot.ply")
print(mesh)
o3d.io.write_triangle_mesh("copy_of_knot.ply",mesh)

>>>>Testing IO for meshes ...
>>>>geometry::TriangleMesh with 1440 points and 2880 triangles.

与点云的数据结构相比,网格(mesh)数据具有定义三维曲面的三角形。与点云数据一样,会自动通过文件类型推断,支持的mesh数据格式如下。

格式描述
ply同点云
stl请看链接
obj请看链接
off请看链接
gltf请看链接

图像(Image)

通过以下代码可以读写图像数据

print("Testing IO for images ...")
img = o3d.io.read_image("../../TestData/lena_color.jpg")
print(img)
o3d.io.write_image("copy_of_lena_color.jpg", img)

>>>>Testing IO for images ...
>>>>Image of size 512x512, with 3 channels.
>>>>Use numpy.asarray to access buffer data.

使用print(img)可以很容易的显示图像的大小。

欢迎大家加入知识星球一起学习。

在这里插入图片描述

  • 23
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值