使用Python的Open3D(Python 3.6.5,Open3D v0.4.0)


开发环境

  • Windows10(64位,16GB内存,i7-7700HQ)
  • Open3D v0.4.0
  • Python 3.6.5

Open3D安装

可以使用以下命令安装Python3.6.x。 (让我们使用anaconda创建py36环境)
单击此处检查可以安装的Python版本。

1
pip install open3d-python

Open3D示例

下载

Open3D v0.4.0,并且\Open3D-0.4.0\examples\Python下有一个示例程序,因此让我们尝试一下。

进阶

camera_trajectory.py

camera_trajectory.png

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
40
41
42
43
44
45
46
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python camera_trajectory.py
Testing camera in open3d ...
[[525.    0.  319.5]
 [  0.  525.  239.5]
 [  0.    0.    1. ]]
PinholeCameraIntrinsic with width = -1 and height = -1.
Access intrinsics with intrinsic_matrix.
PinholeCameraIntrinsic with width = 640 and height = 480.
Access intrinsics with intrinsic_matrix.
[[525.   0. 320.]
 [  0. 525. 240.]
 [  0.   0.   1.]]
PinholeCameraIntrinsic with width = 640 and height = 480.
Access intrinsics with intrinsic_matrix.
[[525.   0. 320.]
 [  0. 525. 240.]
 [  0.   0.   1.]]
Read a trajectory and combine all the RGB-D images.
PinholeCameraTrajectory class.
Access its data via intrinsic and extrinsic.
std::vector<Eigen::Matrix4d> with 5 elements.
Use numpy.asarray() to access data.
[[[-2.73959219e-01  8.67361738e-19 -9.61741310e-01  1.96003743e+00]
  [ 2.18193459e-02 -9.99742609e-01 -6.21540418e-03  5.92858340e-01]
  [-9.61493766e-01 -2.26873336e-02  2.73888704e-01 -8.68039442e-01]
  [ 0.00000000e+00  0.00000000e+00 -0.00000000e+00  1.00000000e+00]]

 [[-2.69333111e-01 -3.46944695e-18 -9.63047079e-01  1.96388301e+00]
  [ 3.32939238e-02 -9.99402229e-01 -9.31123335e-03  6.26082021e-01]
  [-9.62471397e-01 -3.45714395e-02  2.69172111e-01 -8.50365753e-01]
  [ 0.00000000e+00  0.00000000e+00 -0.00000000e+00  1.00000000e+00]]

 [[-2.65351855e-01 -3.46944695e-18 -9.64151644e-01  1.96642986e+00]
  [ 4.52270814e-02 -9.98899182e-01 -1.24473054e-02  6.60222975e-01]
  [-9.63090289e-01 -4.69086805e-02  2.65059750e-01 -8.32396694e-01]
  [ 0.00000000e+00  0.00000000e+00 -0.00000000e+00  1.00000000e+00]]

 [[-2.61914323e-01 -1.73472348e-18 -9.65091129e-01  1.96788675e+00]
  [ 5.75424277e-02 -9.98220917e-01 -1.56163346e-02  6.95070189e-01]
  [-9.63374152e-01 -5.96238282e-02  2.61448356e-01 -8.14014971e-01]
  [ 0.00000000e+00  0.00000000e+00 -0.00000000e+00  1.00000000e+00]]

 [[-2.58918642e-01 -0.00000000e+00 -9.65899134e-01  1.96846002e+00]
  [ 7.01643085e-02 -9.97358120e-01 -1.88082242e-02  7.30411488e-01]
  [-9.63347345e-01 -7.26414447e-02  2.58234610e-01 -7.95113315e-01]
  [ 0.00000000e+00  0.00000000e+00 -0.00000000e+00  1.00000000e+00]]]

Colored_pointcloud_registration.py

<表格>

一个

b

c


<身体>

colored_pointcloud_registration.png

colored_pointcloud_registration_2.png

colored_pointcloud_registration_3.png


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
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python colored_pointcloud_registration.py
1. Load two point clouds and show initial pose
Reading PLY: [========================================] 100%
Reading PLY: [========================================] 100%
2. Point-to-plane ICP registration is applied on original point
   clouds to refine the alignment. Distance threshold 0.02.
RegistrationResult with fitness = 0.974582, inlier_rmse = 0.004220, and correspondence_set size of 62729
Access transformation to get result.
3. Colored point cloud registration
[50, 0.04, 0]
3-1. Downsample with a voxel size 0.04
3-2. Estimate normal.
3-3. Applying colored point cloud registration
RegistrationResult with fitness = 0.876367, inlier_rmse = 0.014578, and correspondence_set size of 2084
Access transformation to get result.
[30, 0.02, 1]
3-1. Downsample with a voxel size 0.02
3-2. Estimate normal.
3-3. Applying colored point cloud registration
RegistrationResult with fitness = 0.866184, inlier_rmse = 0.008760, and correspondence_set size of 7541
Access transformation to get result.
[14, 0.01, 2]
3-1. Downsample with a voxel size 0.01
3-2. Estimate normal.
3-3. Applying colored point cloud registration
RegistrationResult with fitness = 0.843719, inlier_rmse = 0.004851, and correspondence_set size of 24737
Access transformation to get result.

color_map_optimization.py

1。下载喷泉数据集。
2。将下载的喷泉数据集的目录路径添加到[path_to_fountain_dataset]并执行。

<表格>

一个

b


<身体>

color_map_optimization.png

color_map_optimization_2.png


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
40
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python color_map_optimization.py
Reading PLY: [========================================] 100%
Read TriangleMesh: 1033745 triangles and 536872 vertices.
[ColorMapOptimization]
[ColorMapOptimization] :: MakingMasks
[MakeDepthMasks] Image 0/33
...
[MakeDepthMasks] Image 32/33
[ColorMapOptimization] :: VisibilityCheck
[cam 25] 14.76181 percents are visible
...
[cam 4] 38.92045 percents are visible
[ColorMapOptimization] :: Rigid Optimization
GLFW init.
Add geometry and update bounding box to [(0.0015, 0.0015, 0.4771) - (1.4985, 1.4985, 1.4846)]
Global colormap init.
[Visualizer] Screen capture to ScreenCapture_2019-01-16-06-25-11.png
[Visualizer] Screen camera capture to ScreenCamera_2019-01-16-06-25-11.json
Writing PLY: [========================================] 100%
Write TriangleMesh: 1033745 triangles and 536872 vertices.
[ColorMapOptimization]
[ColorMapOptimization] :: MakingMasks
[MakeDepthMasks] Image 0/33
...
[MakeDepthMasks] Image 32/33
[ColorMapOptimization] :: VisibilityCheck
[cam 25] 14.76181 percents are visible
...
[cam 4] 38.92045 percents are visible
[ColorMapOptimization] :: Non-Rigid Optimization
[Iteration 0001] Residual error : 21639.276499, reg : 0.000000
...
[Iteration 0300] Residual error : 5585.115116, reg : 2747.785043
Add geometry and update bounding box to [(0.0015, 0.0015, 0.4771) - (1.4985, 1.4985, 1.4846)]
[Visualizer] Screen capture to ScreenCapture_2019-01-16-06-32-08.png
[Visualizer] Screen camera capture to ScreenCamera_2019-01-16-06-32-08.json
Writing PLY: [========================================] 100%
Write TriangleMesh: 1033745 triangles and 536872 vertices.
Global colormap destruct.
GLFW destruct.

custom_visualization.py

customized_visualization.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python customized_visualization.py
Reading PLY: [========================================] 100%
1. Customized visualization to mimic DrawGeometry
2. Changing field of view
Field of view (before changing) 60.00
Field of view (after changing) 90.00
Field of view (before changing) 60.00
Field of view (after changing) 5.00
[ViewControl] ConvertToPinholeCameraParameters() failed because orthogonal view cannot be translated to a pinhole camera.
3. Customized visualization with a rotating view
4. Customized visualization showing normal rendering
5. Customized visualization with key press callbacks
   Press 'K' to change background color to black
   Press 'R' to load a customized render option, showing normals
   Press ',' to capture the depth buffer and show it
   Press '.' to capture the screen and show it
6. Customized visualization playing a camera trajectory
[ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
Capture image 00000
...

fast_global_registration.py

<表格>

一个

b

c


<身体>

fast_global_registration.png

fast_global_registration_2.png

fast_global_registration_3.png


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python fast_global_registration.py
:: Load two point clouds and disturb initial pose.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: RANSAC registration on downsampled point clouds.
   Since the downsampling voxel size is 0.050,
   we use a liberal distance threshold 0.075.
RegistrationResult with fitness = 0.676891, inlier_rmse = 0.032296, and correspondence_set size of 3222
Access transformation to get result.
Global registration took 0.464 sec.

:: Apply fast global registration with distance threshold 0.025
Fast global registration took 0.218 sec.

global_registration.py

<表格>

一个

b

c


<身体>

global_registration.png

global_registration_2.png

global_registration_3.png


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python global_registration.py
:: Load two point clouds and disturb initial pose.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: Downsample with a voxel size 0.050.
:: Estimate normal with search radius 0.100.
:: Compute FPFH feature with search radius 0.250.
:: RANSAC registration on downsampled point clouds.
   Since the downsampling voxel size is 0.050,
   we use a liberal distance threshold 0.075.
RegistrationResult with fitness = 0.676471, inlier_rmse = 0.028703, and correspondence_set size of 3220
Access transformation to get result.
:: Point-to-plane ICP registration is applied on original point
   clouds to refine the alignment. This time we use a strict
   distance threshold 0.020.
RegistrationResult with fitness = 0.621033, inlier_rmse = 0.006565, and correspondence_set size of 123483
Access transformation to get result.

headless_rendering.py

headless_rendering.png

1
2
3
4
5
6
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python headless_rendering.py
Reading PLY: [========================================] 100%
Customized visualization playing a camera trajectory. Ctrl+z to terminate
[ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
Capture image 00000
...

Interactive_visualization.py

<表格>

一个

b

c

d


<身体>

interactive_visualization.png

interactive_visualization_2.png

interactive_visualization_3.png

interactive_visualization_4.png


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
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python interactive_visualization.py
Demo for manual geometry cropping
1) Press 'Y' twice to align geometry with negative direction of y-axis
2) Press 'K' to lock screen and to switch to selection mode
3) Drag for rectangle selection,
   or use ctrl + left click for polygon selection
4) Press 'C' to get a selected geometry and to save it
5) Press 'F' to switch to freeview mode
Demo for manual ICP
Visualization of two point clouds before manual alignment

1) Please pick at least three correspondences using [shift + left click]
   Press [shift + right click] to undo point picking
2) Afther picking points, press q for close the window


1) Please pick at least three correspondences using [shift + left click]
   Press [shift + right click] to undo point picking
2) Afther picking points, press q for close the window

Traceback (most recent call last):
  File "interactive_visualization.py", line 75, in <module>
    demo_manual_registration()
  File "interactive_visualization.py", line 53, in demo_manual_registration
    assert(len(picked_id_source)>=3 and len(picked_id_target)>=3)
AssertionError

multiway_registration.py

<表格>

一个

b

c


<身体>

multiway_registration.png

multiway_registration_2.png

multiway_registration_3.png


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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
(py36) D:\Open3D-0.4.0\examples\Python\Advanced>python multiway_registration.py
PCD header indicates 8 fields, 32 bytes per point, and 198835 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 198835 vertices.
Pointcloud down sampled from 198835 points to 27211 points.
PCD header indicates 8 fields, 32 bytes per point, and 137833 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 137833 vertices.
Pointcloud down sampled from 137833 points to 19137 points.
PCD header indicates 8 fields, 32 bytes per point, and 191397 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 191397 vertices.
Pointcloud down sampled from 191397 points to 25269 points.
GLFW init.
Add geometry and update bounding box to [(0.5513, 0.8320, 0.5617) - (3.9485, 2.4249, 2.5522)]
Add geometry and update bounding box to [(0.5513, 0.8320, 0.5617) - (3.9485, 2.6123, 2.5522)]
Add geometry and update bounding box to [(0.0039, 0.8320, 0.4857) - (3.9485, 2.9019, 2.5522)]
Global colormap init.
[Visualizer] Screen capture to ScreenCapture_2019-01-16-06-57-01.png
[Visualizer] Screen camera capture to ScreenCamera_2019-01-16-06-57-01.json
[ViewControl] SetViewPoint() failed because window height and width are not set.Full registration ...
Apply point-to-plane ICP
ICP Iteration #0: Fitness 0.6258, RMSE 0.1566
Residual : 1.96e-02 (# of elements : 17029)
...
ICP Iteration #5: Fitness 0.6391, RMSE 0.0101
Residual : 3.22e-05 (# of elements : 17390)
Build PoseGraph
Apply point-to-plane ICP
ICP Iteration #0: Fitness 0.5669, RMSE 0.1655
Residual : 1.86e-02 (# of elements : 15427)
...
ICP Iteration #5: Fitness 0.7054, RMSE 0.0104
Residual : 3.25e-05 (# of elements : 19194)
Build PoseGraph
Apply point-to-plane ICP
ICP Iteration #0: Fitness 0.7980, RMSE 0.1231
Residual : 1.25e-02 (# of elements : 15272)
...
ICP Iteration #4: Fitness 0.7594, RMSE 0.0108
Residual : 4.35e-05 (# of elements : 14532)
Build PoseGraph
Optimizing PoseGraph ...
Validating PoseGraph - finished.
[GlobalOptimizationLM] Optimizing PoseGraph having 3 nodes and 3 edges.
Line process weight : 15.342900
[Initial     ] residual : 1.068329e+00, lambda : 2.960767e+00
[Iteration 00] residual : 2.144428e-01, valid edges : 1, time : 0.000 sec.
[Iteration 01] residual : 1.535337e-01, valid edges : 1, time : 0.000 sec.
Delta.norm() < 1.000000e-06 * (x.norm() + 1.000000e-06)
[GlobalOptimizationLM] total time : 0.008 sec.
[GlobalOptimizationLM] Optimizing PoseGraph having 3 nodes and 3 edges.
Line process weight : 15.342900
[Initial     ] residual : 1.535309e-01, lambda : 3.050809e+00
Delta.norm() < 1.000000e-06 * (x.norm() + 1.000000e-06)
[GlobalOptimizationLM] total time : 0.001 sec.
CompensateReferencePoseGraphNode : reference : 0
Transform points and display
[[ 1.00000000e+00 -1.81265051e-19 -1.08420217e-19  1.73472348e-18]
 [ 3.54695047e-20  1.00000000e+00 -1.08420217e-19  0.00000000e+00]
 [-2.16840434e-19  0.00000000e+00  1.00000000e+00  0.00000000e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
[[ 0.84017249 -0.14644731  0.52217178  0.34783878]
 [ 0.00617134  0.96536884  0.26081585 -0.3942583 ]
 [-0.54228415 -0.2159078   0.81198012  1.73003584]
 [ 0.          0.          0.          1.        ]]
[[ 0.9627123  -0.07179198  0.2608274   0.37654711]
 [-0.00195415  0.96227383  0.27207581 -0.48957983]
 [-0.27052025 -0.26244043  0.92625257  1.29771599]
 [ 0.          0.          0.          1.        ]]
Add geometry and update bounding box to [(0.5513, 0.8320, 0.5617) - (3.9485, 2.4249, 2.5522)]
Add geometry and update bounding box to [(0.5513, 0.8320, 0.5346) - (4.0783, 2.4252, 2.5522)]
Add geometry and update bounding box to [(0.5012, 0.8320, 0.5346) - (4.0783, 2.4442, 2.5522)]
[Visualizer] Screen capture to ScreenCapture_2019-01-16-06-57-33.png
[Visualizer] Screen camera capture to ScreenCamera_2019-01-16-06-57-33.json
Make a combined point cloud
PCD header indicates 8 fields, 32 bytes per point, and 198835 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 198835 vertices.
Pointcloud down sampled from 198835 points to 27211 points.
PCD header indicates 8 fields, 32 bytes per point, and 137833 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 137833 vertices.
Pointcloud down sampled from 137833 points to 19137 points.
PCD header indicates 8 fields, 32 bytes per point, and 191397 points in total.
x, F, 4, 1, 0
y, F, 4, 1, 4
z, F, 4, 1, 8
rgb, F, 4, 1, 12
normal_x, F, 4, 1, 16
normal_y, F, 4, 1, 20
normal_z, F, 4, 1, 24
curvature, F, 4, 1, 28
Compression method is 1.
Points: yes;  normals: yes;  colors: yes
[Purge] 0 nan points have been removed.
Read PointCloud: 191397 vertices.
Pointcloud down sampled from 191397 points to 25269 points.
Pointcloud down sampled from 71617 points to 33315 points.
Write PointCloud: 33315 vertices.
Add geometry and update bounding box to [(0.5012, 0.8335, 0.5346) - (4.0761, 2.4441, 2.5522)]
[Visualizer] Screen capture to ScreenCapture_2019-01-16-06-57-52.png
[Visualizer] Screen camera capture to ScreenCamera_2019-01-16-06-57-52.json
Global colormap destruct.
GLFW destruct.

non_blocking_visualization.py