[Python --open3d] How to convert obj data of 3D model to point cloud

Overview

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.

スクリーンショット 2020-02-15 4.08.42.png スクリーンショット 2020-02-15 4.08.59.png

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.

obj data conversion

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

[Python --open3d] How to convert obj data of 3D model to point cloud
[Python] How to convert a 2D list to a 1D list
How to convert floating point numbers to binary numbers in Python
Acquisition of 3D point cloud with Softbank Pepper (Choregraphe, Python)
How to change python version of Notebook in Watson Studio (or Cloud Pak for Data)
[Python] How to FFT mp3 data
How to update the python version of Cloud Shell on GCP
[Python] How to convert db file to csv
[Python] Summary of how to use pandas
Convert Excel data to JSON with python
Convert FX 1-minute data to 5-minute data with Python
[Python2.7] Summary of how to use unittest
How to switch python versions in cloud9
How to use "deque" for Python data
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
[Introduction to Data Scientists] Basics of Python ♬
[Question] How to use plot_surface of python
How to send a visualization image of data created in Python to Typetalk
[Python] How to change character string (str) data to date (strptime of datetime)
[Tensorflowjs_converter] How to convert Tensorflow model to Tensorflow.js format
[Python] How to use two types of type ()
Convert data with shape (number of data, 1) to (number of data,) with numpy.
Convert "number" of excel date to python datetime
Summary of how to read numerical data with python [CSV, NetCDF, Fortran binary]
Summary of how to import files in Python 3
[Python] How to read data from CIFAR-10 and CIFAR-100
[Introduction to Python] How to handle JSON format data
How to convert SVG to PDF and PNG [Python]
How to specify attributes with Mock of python
How to get dictionary type elements of Python 2.7
[Introduction to Python] How to get the index of data with a for statement
How to convert / restore a string with [] in python
Summary of tools needed to analyze data in Python
How to convert Python # type for Python super beginners: str
How to get the number of digits in Python
I tried to summarize how to use matplotlib of python
[For beginners] How to study Python3 data analysis exam
How to scrape image data from flickr with python
How to convert horizontally held data to vertically held data with pandas
How to visualize the decision tree model of scikit-learn
How to write a list / dictionary type of Python3
How to use Python Kivy ① ~ Basics of Kv Language ~
How to convert JSON file to CSV file with Python Pandas
Python: Diagram of 2D data distribution (kernel density estimation)
[Python] Summary of how to specify the color of the figure
How to use the model learned in Lobe in Python
python, php, ruby How to convert decimal numbers to n-ary numbers
[Python] How to create a 2D histogram with Matplotlib
How to install Python
How to install python
[Question] How to get data of textarea data in real time using Python web framework bottle
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
SIGNATE Quest ② From creation of targeting model to creation of submitted data
[Python] How to make a list of character strings character by character
Offline real-time how to write Python implementation example of E14
How to convert an array to a dictionary with Python [Application]
[python] Summary of how to retrieve lists and dictionary elements
How to shuffle a part of a Python list (at random.shuffle)
How to transpose a 2D array using only python [Note]
How to generate exponential pulse time series data in python