[Lidar] Python-based Open3D library and Laspy library to save point cloud files/point cloud format conversion

        Because I have recently been working on point cloud-related projects, the Open3D library and Laspy library in Python have been used in the process, so today I will share with you how to use Open3D and Laspy to save and format point cloud data.

1 Introduction to Open3D library

        I will introduce the Laspy library separately at that time, so I won’t go into details here! ! !

        Open3D is an open source 3D data processing library, released in 2015, and has been updated to version 0.17.0. It is based on the MIT license open source license, implemented using C++11, and is highly optimized. It also provides a front-end Python API through Python Pybinding. Open3D provides developers with a carefully selected set of data structures and algorithms that are highly optimized internally and set up for parallelization. It handles various applications of 3D data, including point clouds, meshes, volume calculations, visualization, deep learning, measurements and scene graphs, etc. Open3D aims to be an efficient, scalable and easy-to-use 3D data processing library.

2 Point cloud data saving code

2.1 Save laspy library

        In laspy, you can select the corresponding point cloud data through the list index. It should be noted that laspy only supports .las and .laz files.

def save_point(path, point_type):
    # ---------------------------laspy库保存----------------------------
    las = laspy.read(r"Z:\Personal\彭俊喜\Lidar_try/2.las")  # read a las file
    points = las.points
    out_file = laspy.LasData(las.header)
    ground = [2, 5, 6]  # 索引
    out_file.points = points[np.array(ground)]  # extract ground points, and save it to a las file.
    out_file.write(r"Z:\Personal\彭俊喜\Lidar_try/out1.las")

2.2 Open3D library saving/format conversion

        ​ ​ This contains a method to create point cloud data through an array and save it. The point cloud format conversion mentioned in the title is also here. We only need to use the open3d library to read the point cloud and add the corresponding suffix when exporting to perform format conversion.

def save_point(path, point_type):

    # ---------------------------open3d库保存---------------------------
    pcd = o3d.io.read_point_cloud(path, format=point_type, remove_nan_points=True, remove_infinite_points=True, print_progress=True)
    # 路径、输入格式、删除包含NAN的所有点、删除包含无限值的所有点、可视化进度条
    print(pcd)  # 输出点云点的个数
    print(np.asarray(pcd.points))  # 输出点的三维坐标
    o3d.io.write_point_cloud(r'1.xyz', pcd, write_ascii=False, compressed=False, print_progress=True)
    # 路径、文件、以ascii格式输出否则使用二进制输出、以压缩格式写入、可视化进度条

    # ---------------------------open3d库保存---------------------------
    numpy = [[1, 2, 3], [1, 2, 3], [3, 4, 5]]
    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(numpy)  # 数组转点云
    o3d.io.write_point_cloud(r'Z:\Personal\彭俊喜\Lidar_try/1.xyz', pcd, write_ascii=False, compressed=False,
                             print_progress=True)

3 Summary

        At present, I use Open3D and Laspy two libraries to process point cloud data. Personally, I think these two libraries are quite good. I will continue to update more tutorials on Python processing point cloud data in the future, such as point cloud clustering, Single wood segmentation, etc. If you are interested, you can follow me. There is currently no idea of ​​setting it as a paid column, so you can rest assured to learn.

Guess you like

Origin blog.csdn.net/m0_56729804/article/details/134779581