|
|
https://www.open3d.org/docs/release/python_api/open3d.geometry.TriangleMesh.html
Open3d 바운딩 박스의 length, width, height의 정의는 무엇인가?
Create OrientedBoudingBox from center, rotation R and extent in x, y and z direction
중심점 (x, y, z) 기준으로 length, width, height 범위만큼 바운딩 박스 생성함
과제: LineSet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import open3d as o3d import numpy as np points = [] lines = [] colors = [] # 격자 설정 gap = 0.2 # 한 칸 간격 num_lines = 11 # 0~10까지 half_range = 1 # -1부터 1까지의 좌표 범위 # Z 방향으로 X축 선 (빨간색) for i in range(num_lines): z = -half_range + i * gap # -1~1 범위에서 gap 간격으로 이동 points.append([-half_range, 0, z]) # 좌표 append points.append([half_range, 0, z]) idx = len(points) lines.append([idx - 2, idx - 1]) # 두 점 연결 colors.append([1, 0, 0]) # red # X 방향으로 Z축 선 (파란색) for i in range(num_lines): x = -half_range + i * gap points.append([x, 0, -half_range]) points.append([x, 0, half_range]) idx = len(points) lines.append([idx - 2, idx - 1]) colors.append([0, 0, 1]) # blue line_set = o3d.geometry.LineSet() line_set.points = o3d.utility.Vector3dVector(points) line_set.lines = o3d.utility.Vector2iVector(lines) line_set.colors = o3d.utility.Vector3dVector(colors) axis_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1) o3d.visualization.draw_geometries([line_set, axis_frame], width=500, height=500) | cs |
과제: TriangleMesh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import open3d as o3d import numpy as np mesh_sphere1 = o3d.geometry.TriangleMesh.create_sphere(radius=1.0) mesh_sphere1.translate([2,0,0]) mesh_sphere1.compute_vertex_normals() mesh_sphere1.paint_uniform_color([0.1, 0.1, 0.7]) mesh_box = o3d.geometry.TriangleMesh.create_box(width=1.0,height=1.0,depth=1.0) mesh_box.translate([3,0,0]) mesh_box.compute_vertex_normals() mesh_box.paint_uniform_color([0.9, 0.1, 0.1]) mesh_sphere2 = o3d.geometry.TriangleMesh.create_sphere(radius=1.0) mesh_sphere2.translate([5,0,0]) mesh_sphere2.compute_vertex_normals() mesh_sphere2.paint_uniform_color([0.1, 0.1, 0.7]) min_bound = np.array([1.0, -1.0, -1.0]) max_bound = np.array([6.0, 1.0, 1.0]) aabb = o3d.geometry.AxisAlignedBoundingBox(min_bound=min_bound, max_bound=max_bound) aabb.color = (1, 0, 0) # 빨간색 mesh_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=1, origin=[0, 0, 0]) o3d.visualization.draw_geometries([aabb, mesh_box, mesh_sphere1, mesh_sphere2, mesh_frame],width=500,height=500) | cs |
과제: AxisAlignedBoundingBox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import open3d as o3d import numpy as np # AABB 경계 설정 min_bound = np.array([0.0, 0.0, 0.0]) max_bound = np.array([1.0, 2.0, 3.0]) # AABB 생성 및 색상 aabb = o3d.geometry.AxisAlignedBoundingBox(min_bound, max_bound) aabb.color = (0, 0, 0) points = np.array(aabb.get_box_points()) lines = [ [0, 7], [1, 2], [3, 4], [5, 6], ] colors = [[1, 0, 0]] * 4 # 빨간색 4개 diagonals = o3d.geometry.LineSet() diagonals.points = o3d.utility.Vector3dVector(points) diagonals.lines = o3d.utility.Vector2iVector(lines) diagonals.colors = o3d.utility.Vector3dVector(colors) axis_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5) o3d.visualization.draw_geometries([aabb, diagonals, axis_frame], width=500, height=500) | cs |
과제: OrientedBoundingBox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import open3d as o3d import numpy as np # 모든 center point를 0, 0, 0으로 설정 center = np.array([0, 0, 0]) axis_angles = np.array([0, 0, 0]) rotation = o3d.geometry.get_rotation_matrix_from_axis_angle(axis_angles) extent = np.array([1, 1, 1]) obb = o3d.geometry.OrientedBoundingBox(center, rotation, extent) obb.color = [1, 0, 0] points = np.array(obb.get_box_points()) lines = [ [0, 7], [1, 2], [3, 4], [5, 6], ] colors = [[1, 0, 0]] * 4 # 빨간색 4개 diagonals = o3d.geometry.LineSet() diagonals.points = o3d.utility.Vector3dVector(points) diagonals.lines = o3d.utility.Vector2iVector(lines) diagonals.colors = o3d.utility.Vector3dVector(colors) axis_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5, origin=[0, 0, 0]) o3d.visualization.draw_geometries([obb, diagonals, axis_frame], width=500, height=500) | cs |
과제: Crop PointCloud
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import open3d as o3d import numpy as np pcd= o3d.geometry.PointCloud() np_points= np.random.rand(100, 3) pcd.points= o3d.utility.Vector3dVector(np_points) aabb1 = pcd.get_axis_aligned_bounding_box() aabb1.color= [1, 0, 0] y_center = aabb1.get_center()[1] # [x_center, y_center, z_center]를 반환함 y기준만 쓸거니까 [1] 꺼내서 씀 filtered_points = [] for point in np_points: if point[1] <= y_center: filtered_points.append(point) filtered_points = np.array(filtered_points) filtered_pcd = o3d.geometry.PointCloud() filtered_pcd.points = o3d.utility.Vector3dVector(filtered_points) aabb2 = filtered_pcd.get_axis_aligned_bounding_box() aabb2.color = [0, 1, 0] axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5, origin=[0, 0, 0]) o3d.visualization.draw_geometries([filtered_pcd ,axis_frame,aabb1, aabb2], width=500,height=500) | cs |
과제: Project PointCloud
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import open3d as o3d import numpy as np pcd = o3d.geometry.PointCloud() np_points = np.random.rand(100, 3) np_points[:, 0] = 0 # np_points[:, 1] = 0 # np_points[:, 2] = 0 pcd.points = o3d.utility.Vector3dVector(np_points) axis_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5, origin=[0, 0, 0]) o3d.visualization.draw_geometries([pcd, axis_frame], width=500,height=500) | cs |