1
2

More than 1 year has passed since last update.

Open3Dで点群のAABBとOBBを可視化する

Posted at

たまに必要になるものの、Cloud CompareやMesh labで簡単に値をゲットする方法がなさそうなのでメモ書き。
plyの部分は適当に読み替えてください。


import sys
import numpy as np
import open3d as o3d
import sys

ply = o3d.io.read_point_cloud("xxx.ply")
point_array = np.array(ply.points)

lines = [
   [0, 1],
   [0, 2],
   [0, 3],
   [1, 7],
   [1, 6],
   [2, 7],
   [2, 5],
   [3, 6],
   [3, 5],
   [4, 5],
   [4, 6],
   [4, 7],
]

aabb = ply.get_axis_aligned_bounding_box()
vta = np.asarray(aabb.get_box_points())
print("aabb\n", np.asarray(vta))

colors = [[1, 0, 0] for i in range(len(lines))]
line_set = o3d.geometry.LineSet(
   points=o3d.utility.Vector3dVector(vta),
   lines=o3d.utility.Vector2iVector(lines),
)
line_set.colors = o3d.utility.Vector3dVector(colors)

obb = ply.get_oriented_bounding_box()
vtobb = np.asarray(obb.get_box_points())
print("obb\n", np.asarray(vtobb))


colors_obb = [[0, 0, 1] for i in range(len(lines))]
line_set_obb = o3d.geometry.LineSet(
   points=o3d.utility.Vector3dVector(vtobb),
   lines=o3d.utility.Vector2iVector(lines),
)
line_set_obb.colors = o3d.utility.Vector3dVector(colors_obb)

# red = AABB line color
# blue = OBB line color
o3d.visualization.draw_geometries([ply, line_set, line_set_obb])
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2