[PYTHON] Open3D basics and point cloud voxels

Introduction

I touched on Open3D in my graduation research, but when I first started touching Open3D, I was in trouble because there was too little Japanese information, so I will summarize it a little.

A site that most people who have started to touch Open3D will probably reach → Open3D: http://lang.sist.chukyo-u.ac.jp/classes/Open3D/ This is a Japanese translation of the official tutorial, but there are many things you can do besides the tutorial. If you have something you want to do, you can usually find it in the Official Documentation (http://www.open3d.org/docs/release/index.html).

In my research, I did "point cloud generation from RGB-D camera images", "removal of outliers", "point cloud alignment", etc. Other things I did were "voxelization of point clouds" and "plane estimation using RANSAC".

This time, I will write about the basics of Open3D and "voxelization of point clouds" (although it is just an introduction to functions).

environment

Please note that the specifications of Open3D differ greatly depending on the version. In this article, it is described for v0.9.0, but since I also used v0.7.0 for my research, I have only checked the minimum operation with v0.9.0.

Open3D basics

Point cloud generation and visualization from RGB-D images, reading and writing to pcd files

Point cloud generation from RGB-D images

box.png The upper right is the image acquired from RealSense, and the left is the point cloud generated (in the research, the point cloud was generated after cutting the image).

import open3d as o3d

"""
RGB to Open3D-D image input
"""
color = o3d.Image(color_numpy) #Convert from numpy array
depth = o3d.Image(depth_numpy)
rgbd = o3d.geometry.RGBDImage.create_rgbd_image_from_color_and_depth(color, depth, convert_rgb_to_intensity=False)
pcd = o3d.geometry.PointCloud.create_point_cloud_from_rgbd_image(rgbd, pinhole_camera_intrinsic)
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) #Rotation for easy viewing

You can get pinhole_camera_intrinsic by the following method if you use RealSense. Processing such as RealSense settings is omitted.

import pyrealsense2 as rs

#Get camera intrinsics
intr = profile.get_stream(rs.stream.color).as_video_stream_profile().get_intrinsics()
pinhole_camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(intr.width, intr.height, intr.fx, intr.fy, intr.ppx, intr.ppy)

Point cloud visualization

o3d.visualization.draw_geometries([pcd])

It is also used for visualization of voxels and meshes as well as point clouds.

Reading and writing to pcd files

writing

#Writing in binary
o3d.io.write_point_cloud("hoge.pcd", pcd)

#Writing in ascii
o3d.io.write_point_cloud("hoge.pcd", pcd, True)

You can output other than pcd files. It is convenient to output ascii because it is easy to see.

Read

pcd = o3d.io.read_point_cloud("./hoge.pcd")

Voxelization of point cloud

voxel = o3d.geometry.VoxelGrid.create_from_point_cloud(pcd, 0.03) #Voxel size specification
o3d.visualization.draw_geometries([voxel])

2020-02-25 (2).png

When I touched Open3D, I created a voxelization function for the point cloud by myself, but it seems that it was originally prepared. .. ..

in conclusion

This time I summarized the basics of Open3D. If I have time, I would like to summarize my research and plane estimation with RANSAC, but I probably won't.

Recommended Posts

Open3D basics and point cloud voxels
PointNet theory and implementation (point cloud data)
Perceptron basics and implementation
Point Cloud with Pepper
Python basics: conditions and iterations
[Day 5] View and template basics