현재 apple에서도 TOF카메라를 사용 중이며, 삼성에서도 점차 TOF를 늘리는 추세이지만 이를 다루는 기술에 대한 자료가 부족한 것 같아서 open3D에 대해서 study한 자료를 공유하려고 합니다.
3D 파일은 보통 ply, pcd, obj 파일인 경우가 많습니다.
point_cloud : 어떠한 3D이미지들을 무수한 점들의 모임이라고 했을 때, 각 점들의 좌표(x, y, z)들을 모은 데이터
ex) [[0, 0, 0], [0, 0.1, 0.2], ...]
mesh : point cloud의 점들을 이어 준 것(보통 삼각형으로 모인 경우가 많음)
textured mesh : mesh 데이터의 면을 채워준 것(우리가 소위 생각하는 3D 데이터가 여기 속하는 경우가 많음
pip3 install open3d
import open3d as o3d
import numpy as np
help()
를 통해서 함수에 대한 자세한 설명을 볼 수 있습니다.
def example_help_function():
help(o3d)
help(o3d.geometry.PointCloud)
help(o3d.io.read_point_cloud)
example_help_function()
read_~~ : 파일 경로를 받아서 read해줌
Tip) 이를 print할 경우 데이터에 대한 정보를 볼 수 있음
example -
Point Cloud : PointCloud with 113662 points.
Triangle Mesh : TriangleMesh with 1440 points and 2880 triangles.
print(np.asarray(pcd.points)) :
[[-0.140876 -0.109559 -0.113402 ][-0.14205 -0.109747 -0.114436 ]
[-0.143503 -0.109672 -0.114065 ]
...
[ 0.27193369 0.04444951 -0.16803569][ 0.53305725 -0.06252106 -0.09055633]
[ 0.53918236 -0.0625495 -0.09061065]]
code example -
# point cloud
pcd = o3d.io.read_point_cloud("./test1.ply")
print(pcd)
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
# mesh
mesh = o3d.io.read_triangle_mesh("./test2.ply")
print(mesh)
o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)
# textured mesh
textured_mesh = o3d.io.read_triangle_mesh("./test1.obj")
print(textured_mesh)
o3d.io.write_triangle_mesh("copy_of_crate.obj",
textured_mesh,
write_triangle_uvs=True)
copy_textured_mesh = o3d.io.read_triangle_mesh('copy_of_crate.obj')
print(copy_textured_mesh)
# image
img = o3d.io.read_image("../../TestData/lena_color.jpg")
print(img)
o3d.io.write_image("copy_of_lena_color.jpg", img)
이렇게 포인트 클라우드를 불러오고 저장하는 것을 먼저 살펴보았는데요.
다음 포스팅에선 이미지를 visualize 하는 방법을 살펴보겠습니다.