CAFE

특강게시판

open3d 1-3주차 (open3d geometry)

작성자조건우|작성시간25.07.07|조회수23 목록 댓글 0

모듈별 정리 (io / visualization / geometry)

 

open3d.io : 모듈 : 파일 입출력과 관련된 함수와 클래스를 모아 놓은 모듈
open3d.io.<멤버함수> : read_triangle_mesh / read_line_set / write_point_cloud

 


open3d.visualization모듈 : 3차원 데이터(pcd, mesh)를 시각화하기 위한 클래스와 함수들을 제공하는 open3d 모듈

geometry_list: 시각화 할 geometry(3차원 기하학적 도형)의 리스트 (ply/pcd 파일로 불러온 도형 & 좌표계 등)

window_name: 윈도우 이름

width & height: 시각화 윈도우의 폭 & 높이

 

lookat: 카메라가 바라보는 대상 위치 (월드 좌표계 기준)

up: 카메라 좌표계의 수직(up) 축

front: 카메라가 바라보는 방향 벡터

zoom: (확대/축소 비율, 작을수록 확대됨)

open3d.visualization.draw_geometries 함수 : 시각화 (+시점 조정)

  - up벡터와 front벡터는 수직 관계임 (두 벡터의 내적=0) (front=[1,1,1], up=[-1,2,-1])

  - Camera position vector = lookat + (zoom * front)

 

- open3d.visualization.Visualizer클래스 : draw_geometries 함수보다 세밀

 

 

•  open3d.geometry모듈 : 3차원 기하학적인 데이터를 처리하기 위한 클래스와 함수들을 제공하는 open3d 모듈
open3d.geometry.<클래스> : LineSet / TriangleMesh / AxisAlignedBoundingBox / PointCloud / VoxelGrid
  - open3d.geometry.LineSet : 객체 생성시 멤버변수(points, lines) 정의 필요 ("colors"는 인자x)

     - points type : open3d.utility.Vector3dVector (float64 array of shape) np.array일 때는 인자x (lines → 인자x)

     - lines type : open3d.utility.Vector2iVector (int array of shape)

     - colors type : open3d.utility.Vector3dVector (float64 array of shape) 인자x


  - open3d.geometry.TriangleMesh
     - open3d.geometry.TriangleMesh.<멤버함수> : create_coordinate_frame / create_box / create_cylinder / create_sphere

       반환형 → open3d.geometry.TriangleMesh

        - (생략..)create_coordinate_frame(size, origin) : 3차원 좌표축 생성

        - (생략..)create_box(width, height, depth) : 직육면체 생성

        + open3d.geometry.TriangleMesh(객체).<멤버함수>

            - (생략..)translate([X,Y,Z]) : 3D 객체의 중점으로부터 이동

            - (생략..)compute_vertex_normals() : 명암

            - (생략..)paint_uniform_color([r,g,b]) : 0~1 범위 실수

 

(아래 추가 설명..)

  - open3d.geometry. AxisAlignedBoundingBox : 객체 생성시 멤버변수(min_bound, max_bound) 정의 필요 ("color"는 인자x)

     - min_bound : numpy.array([x,y,z])

     - max_bound : numpy.array([x,y,z])

     - color : [r,g,b] (0~1 float type)

     + open3d.geometry. AxisAlignedBoundingBox(객체).<멤버함수>

         - (생략..)get_box_points(): numpy로 변환시켜 출력해야 됨

         - (생략..)get_center(): 직육면체 중앙좌표(position) 출력

         - (생략..)get_extent()

 

  - open3d.geometry.OrientedBoundingBox : 객체 생성시 멤버변수(center, rotation, extent) 정의 필요 ("color"는 인자x)

     - center : numpy.array([x,y,z])

     - rotation : 바운딩박스 중심에서 x,y,z축 방향의 회전각도 (아래의 함수를 이용하여 구함)

        - open3d.geometry.get_rotation_matrix_from_axis_angle(numpy.float64[3,1])
          반환형 → numpy.ndarray[numpy.float64[3,3]]  (ndarray란? numpy의 N차원 배열 객체)

 

 

     - extent : numpy.array([x,y,z])

     - color : [r,g,b] (0~1 float type)

 

 

 

 

  - open3d.geometry.PointCloud : 객체 생성 후 멤버변수(points, color, normals) 정의

     - points type : open3d.utility.Vector3dVector(numpy_points) (자료형: float64 array of shape)

     + open3d.geometry.PointCloud(객체).<멤버함수>

         - (생략..)get_axis_aligned_bounding_box : Point Cloud를 둘러싸는 AABB를 리턴

         - (생략..)get_minimal_oriented_bounding_box : Point Cloud를 둘러싸는 최소의 OBB를 리턴

         - (생략..)get_oriented_bounding_box : Point Cloud를 둘러싸는 OBB를 리턴

         + (생략....)color : [r,g,b] (0~1 float type)

 

 


 

3D bounding box: 3차원 객체를 포함하는 최소 부피의 직육면체

- AABB (Axis-Aligned Bounding Box)

  - 3차원 객체의 모든 점을 포함하는 최소크기의 직육면체 중 각 변이 x,y,z축에 평행

  - min(좌측하단 꼭지점)과 max(우측상단 꼭지점)로 정의

- OBB (Oriented Bounding Box)

  - 임의의 방향을 갖는 3차원 직육면체이고, 각 변이 x,y,z축에 평행하지 않음 → 3D 객체를 둘러싸는 최소 부피의 직육면체

  - (x,y,z): 중심좌표 / R: 회전행렬 / (length, width, height): x,y,z축 방향의 크기로 정의

     - R(rotation): 회전행렬은 바운딩 박스의 방향을 정의하는 파라미터 (함수를 이용하여 구함)

 

 

 

 

 

 

1. Open3d 좌표의 단위는 무엇인가?

meter 단위로 사용됨

 

2. Open3d 각도의 단위는 무엇인가?

radian 단위로 사용됨 (회전 행렬인 get_rotation_matrix_from_axis_angle 함수)

 

3. Open3d 컬러를 정의하는 방법은?

RGB 3채널 형식으로 지원됨 (0~1, float)

 

4. Open3d.geometry.TriangleMesh.create_box의 width, height, depth의 정의를 설명하시오. 각 인자의 축의 방향을 설명하시오.

static create_box(width: float = 1.0, height: float = 1.0, depth: float = 1.0, …)

- width: x축 방향의 길이

- height: y축 방향의 길이

- depth: z축 방향의 길이

 

5. Open3d 바운딩박스의 length, width, height의 정의는 무엇인가?

- length: x축 방향의 길이

- width: y축 방향의 길이

- height: z축 방향의 길이

 

 

문제 6번.

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
import open3d as o3d
 
points = []
lines = []
colors = []
 
itv = 0.2
index = 0
 
for i in range(11):
    # x,y축 고정 / z축 이동
    points.append([-10-1 + (itv * i)])
    points.append([10-1 + (itv * i)])
    lines.append([2 * index, 2 * index + 1])
    colors.append([1,0,0])
    index += 1
 
    # y,z축 고정 / x축 이동
    points.append([-1 + (itv * i), 0-1])
    points.append([-1 + (itv * i), 01])
    lines.append([2 * index, 2 * index + 1])
    colors.append([0,0,1])
    index += 1
 
line_set= o3d.geometry.LineSet(o3d.utility.Vector3dVector(points), o3d.utility.Vector2iVector(lines))
line_set.colors= o3d.utility.Vector3dVector(colors)
 
axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=1, origin=[0,0,0])
o3d.visualization.draw_geometries([line_set, axis_frame],width=500,height=500)
cs

 

문제 7번.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import open3d as o3d
 
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([1,0,0])
 
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,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,0,1])
 
combined_mesh = mesh_box + mesh_sphere1 + mesh_sphere2
combined_bbox = combined_mesh.get_axis_aligned_bounding_box()
combined_bbox.color = [1,0,0]
 
mesh_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=1,origin=[0,0,0])
 
o3d.visualization.draw_geometries([combined_bbox, mesh_box, mesh_sphere1, mesh_sphere2, mesh_frame],width=500,height=500)
cs

 

문제 8번.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import open3d as o3d
import numpy as np
 
min_bound= np.array([0.00.00.0])
max_bound= np.array([1.02.03.0])
 
aabb= o3d.geometry.AxisAlignedBoundingBox(min_bound=min_bound, max_bound=max_bound)
aabb.color= [0,0,0]
 
points = np.array(aabb.get_box_points()) #numpy 변환
lines = [
    [07],
    [12],
    [34],
    [56]
]
colors = [[100for i in range(len(lines))]
 
line_set= o3d.geometry.LineSet(o3d.utility.Vector3dVector(points), o3d.utility.Vector2iVector(lines))
line_set.colors= o3d.utility.Vector3dVector(colors)
 
axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5, origin=[000])
o3d.visualization.draw_geometries([line_set, aabb,axis_frame], width=500, height=500)
cs

 

문제 9번.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import open3d as o3d
import numpy as np
 
min_bound= np.array([-1,-1,-1])
max_bound= np.array([111])
 
aabb= o3d.geometry.AxisAlignedBoundingBox(min_bound=min_bound, max_bound=max_bound)
aabb.color= [1,0,0]
 
points = np.array(aabb.get_box_points())
lines = [
    [07],
    [12],
    [34],
    [56]
]
colors = [[100for i in range(len(lines))]
 
line_set= o3d.geometry.LineSet(o3d.utility.Vector3dVector(points), o3d.utility.Vector2iVector(lines))
line_set.colors= o3d.utility.Vector3dVector(colors)
 
axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=1,origin=[000])
o3d.visualization.draw_geometries([line_set, aabb,axis_frame],width=500,height=500)
cs

 

문제 10번.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import open3d as o3d
import numpy as np
 
pcd= o3d.geometry.PointCloud()
np_points= np.random.rand(1003#(x,y,z)
pcd.points= o3d.utility.Vector3dVector(np_points)
 
aabb1 = pcd.get_axis_aligned_bounding_box()
aabb1.color= [1,0,0]
 
min_bound = aabb1.get_min_bound()
max_bound = aabb1.get_max_bound()
y_center = (min_bound[1+ max_bound[1]) / 2 #y축 1/2
 
np_points = np_points[np_points[:, 1<= y_center]
half_pcd = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(np_points))
aabb2 = half_pcd.get_axis_aligned_bounding_box()
aabb2.color = [0,1,0]
 
axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5,origin=[000])
o3d.visualization.draw_geometries([half_pcd, axis_frame, aabb1, aabb2],width=500,height=500)
cs

 

 

문제 11번.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import open3d as o3d
import numpy as np
 
np_points= np.random.rand(1003)
 
np_points[: ,1= 0     #zx 평면으로 투영
# np_points[: ,0] = 0   #yz 평면으로 투영
# np_points[: ,2] = 0   #xy 평면으로 투영
 
pcd= o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np_points)
 
axis_frame= o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5,origin=[000])
o3d.visualization.draw_geometries([pcd, axis_frame],width=500,height=500)
cs

 

다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼