This article shows how to convert a model created by Blender etc. into point cloud data used for topology data analysis etc. Although python rarely handles point clouds, it may be used for analysis because there is a good library in the analysis field such as topology data analysis. When using obj data for the analysis, it is necessary to read it with open3D and convert it to a point cloud, so describe it.
It came out after a little research, so it's for memorandum.
open3d
A library that analyzes point cloud data. Basically, you can match point clouds and analyze outliers. It is also possible to build a point cloud group from RGBD data including Depth information.
Data is rarely distributed in point cloud (ply) format, and 3D models are read in formats such as obj and fbx. Therefore, it can be converted to a point cloud by extracting only the vertices (vertices) of obj data and removing the mesh information as shown in the program below.
import open3d as o3d
import numpy as np
def obj_mesh(path):
return o3d.io.read_triangle_mesh(path)
def draw_mesh(mesh):
mesh.paint_uniform_color([1., 0., 0.])
mesh.compute_vertex_normals()
o3d.visualization.draw_geometries([mesh])
def mesh2ply(mesh):
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np.asarray(mesh.vertices))
return pcd
if __name__ == "__main__":
path = "/Users/washizakikai/data/obj3d/IronMan.obj"
mesh = obj_mesh(path)
pcd = mesh2ply(mesh)
Recommended Posts