o3dvis 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- o3dvis-0.1.0/LICENSE +202 -0
- o3dvis-0.1.0/PKG-INFO +15 -0
- o3dvis-0.1.0/o3dvis/__init__.py +8 -0
- o3dvis-0.1.0/o3dvis/config.py +1 -0
- o3dvis-0.1.0/o3dvis/draw.py +222 -0
- o3dvis-0.1.0/o3dvis/player.py +29 -0
- o3dvis-0.1.0/o3dvis/server.py +30 -0
- o3dvis-0.1.0/o3dvis/visualizer.py +202 -0
- o3dvis-0.1.0/o3dvis.egg-info/PKG-INFO +15 -0
- o3dvis-0.1.0/o3dvis.egg-info/SOURCES.txt +14 -0
- o3dvis-0.1.0/o3dvis.egg-info/dependency_links.txt +1 -0
- o3dvis-0.1.0/o3dvis.egg-info/requires.txt +2 -0
- o3dvis-0.1.0/o3dvis.egg-info/top_level.txt +1 -0
- o3dvis-0.1.0/setup.cfg +4 -0
- o3dvis-0.1.0/setup.py +29 -0
- o3dvis-0.1.0/tests/test_draw.py +219 -0
o3dvis-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
o3dvis-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: o3dvis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: open3d visualization toolkit
|
|
5
|
+
Home-page: https://github.com/castle945
|
|
6
|
+
Author: castle945
|
|
7
|
+
Author-email: castle945@njust.edu.cn
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: rpyc
|
|
10
|
+
Requires-Dist: pillow
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rpc_server_ip, rpc_server_port = '127.0.0.1', 30570
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# Copyright (c) castle945. All rights reserved.
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from .utils import (
|
|
5
|
+
read_image,
|
|
6
|
+
read_pickle,
|
|
7
|
+
read_points,
|
|
8
|
+
rpc_func,
|
|
9
|
+
transform_points,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@rpc_func
|
|
14
|
+
def draw_cloud(
|
|
15
|
+
points: dict | np.ndarray = None,
|
|
16
|
+
point_type: str = 'XYZI',
|
|
17
|
+
point_transform: np.ndarray = None,
|
|
18
|
+
point_labels: np.ndarray = None,
|
|
19
|
+
point_colormap: list | np.ndarray = None,
|
|
20
|
+
bboxes3d: np.ndarray = None,
|
|
21
|
+
bboxes3d_labels: np.ndarray = None,
|
|
22
|
+
bboxes3d_colormap: list | np.ndarray = None,
|
|
23
|
+
vis: dict | object = dict(
|
|
24
|
+
type='Visualizer',
|
|
25
|
+
window_name='Cloud Viewer',
|
|
26
|
+
background_color=np.zeros(3),
|
|
27
|
+
point_size=1),
|
|
28
|
+
show: bool = True,
|
|
29
|
+
**kwargs,
|
|
30
|
+
):
|
|
31
|
+
import open3d as o3d
|
|
32
|
+
|
|
33
|
+
from .utils.open3d_utils import (
|
|
34
|
+
create_bboxes3d_geometry,
|
|
35
|
+
create_pointcloud_geometry,
|
|
36
|
+
)
|
|
37
|
+
from .visualizer import VISUALIZERS
|
|
38
|
+
|
|
39
|
+
if show and isinstance(vis, dict):
|
|
40
|
+
vis = VISUALIZERS[vis.pop('type')]().create_window(**vis)
|
|
41
|
+
|
|
42
|
+
if points is not None:
|
|
43
|
+
points = read_points(**points) if isinstance(points, dict) else points
|
|
44
|
+
if point_transform is not None:
|
|
45
|
+
points[:, :3] = transform_points(points[:, :3], point_transform)
|
|
46
|
+
cloud_geometry = create_pointcloud_geometry(
|
|
47
|
+
points, labels=point_labels, colormap=point_colormap, point_type=point_type,
|
|
48
|
+
)
|
|
49
|
+
vis.add_geometry(cloud_geometry, name='points')
|
|
50
|
+
|
|
51
|
+
if bboxes3d is not None:
|
|
52
|
+
bboxes3d_geometry = create_bboxes3d_geometry(
|
|
53
|
+
bboxes3d, labels=bboxes3d_labels, colormap=bboxes3d_colormap, draw_heading=True,
|
|
54
|
+
)
|
|
55
|
+
vis.add_geometry(bboxes3d_geometry, name='bboxes3d')
|
|
56
|
+
|
|
57
|
+
if show:
|
|
58
|
+
axis_geometry = o3d.geometry.TriangleMesh.create_coordinate_frame(size=3.0, origin=[0, 0, 0])
|
|
59
|
+
vis.add_geometry(axis_geometry, name='axis')
|
|
60
|
+
vis.run()
|
|
61
|
+
vis.destroy_window()
|
|
62
|
+
|
|
63
|
+
@rpc_func
|
|
64
|
+
def draw_voxel(
|
|
65
|
+
voxel_centers: np.ndarray = None,
|
|
66
|
+
voxel_size: np.ndarray = None,
|
|
67
|
+
voxel_semantics: np.ndarray = None,
|
|
68
|
+
voxel_colormap: list | np.ndarray = [[0, 1, 0]],
|
|
69
|
+
voxel_transform: np.ndarray = None,
|
|
70
|
+
vis: dict | object = dict(
|
|
71
|
+
type='Visualizer',
|
|
72
|
+
window_name='Voxel Viewer',
|
|
73
|
+
background_color=np.ones(3),
|
|
74
|
+
point_size=10),
|
|
75
|
+
show: bool = True,
|
|
76
|
+
**kwargs,
|
|
77
|
+
):
|
|
78
|
+
import open3d as o3d
|
|
79
|
+
|
|
80
|
+
from .utils.open3d_utils import (
|
|
81
|
+
create_pointcloud_geometry,
|
|
82
|
+
create_voxels_geometry,
|
|
83
|
+
)
|
|
84
|
+
from .visualizer import VISUALIZERS
|
|
85
|
+
if show and isinstance(vis, dict):
|
|
86
|
+
vis = VISUALIZERS[vis.pop('type')]().create_window(**vis)
|
|
87
|
+
|
|
88
|
+
if voxel_centers is not None:
|
|
89
|
+
if voxel_transform is not None:
|
|
90
|
+
voxel_centers[:, :3] = transform_points(voxel_centers[:, :3], voxel_transform)
|
|
91
|
+
voxel_centers_geometry = create_pointcloud_geometry(
|
|
92
|
+
voxel_centers, labels=voxel_semantics, colormap=voxel_colormap,
|
|
93
|
+
)
|
|
94
|
+
vis.add_geometry(voxel_centers_geometry, name='voxel_centers')
|
|
95
|
+
|
|
96
|
+
voxel_grids_geometry = create_voxels_geometry(
|
|
97
|
+
voxel_centers=voxel_centers, voxel_size=voxel_size, colormap=[[0, 0, 0]],
|
|
98
|
+
)
|
|
99
|
+
vis.add_geometry(voxel_grids_geometry, name='voxels')
|
|
100
|
+
|
|
101
|
+
if show:
|
|
102
|
+
axis_geometry = o3d.geometry.TriangleMesh.create_coordinate_frame(size=3.0, origin=[0, 0, 0])
|
|
103
|
+
vis.add_geometry(axis_geometry, name='axis')
|
|
104
|
+
vis.run()
|
|
105
|
+
vis.destroy_window()
|
|
106
|
+
|
|
107
|
+
@rpc_func
|
|
108
|
+
def draw_images(
|
|
109
|
+
images: list[dict | np.ndarray] = None,
|
|
110
|
+
vis: dict | object = dict(
|
|
111
|
+
type='MMVisualizer',
|
|
112
|
+
window_name='Image Viewer',
|
|
113
|
+
background_color=np.zeros(3),
|
|
114
|
+
layout=[[-1]]),
|
|
115
|
+
show: bool = True,
|
|
116
|
+
image_transform: list[np.ndarray] = None,
|
|
117
|
+
with_bboxes3d: bool = False,
|
|
118
|
+
with_points: bool = False,
|
|
119
|
+
**kwargs,
|
|
120
|
+
):
|
|
121
|
+
from .visualizer import VISUALIZERS
|
|
122
|
+
if show and isinstance(vis, dict):
|
|
123
|
+
vis = VISUALIZERS[vis.pop('type')]().create_window(**vis)
|
|
124
|
+
|
|
125
|
+
if images is not None:
|
|
126
|
+
assert type(vis).__name__ in ['MMVisualizer'], f'{type(vis).__name__} does not support image visualization.'
|
|
127
|
+
images = (
|
|
128
|
+
[read_image(img['path']) for img in images]
|
|
129
|
+
if isinstance(images, list) and isinstance(images[0], dict) else images)
|
|
130
|
+
for i, image in enumerate(images):
|
|
131
|
+
vis.update_image(image, widgetId=i+1)
|
|
132
|
+
|
|
133
|
+
if show:
|
|
134
|
+
vis.run()
|
|
135
|
+
vis.destroy_window()
|
|
136
|
+
|
|
137
|
+
@rpc_func
|
|
138
|
+
def draw(
|
|
139
|
+
path: str = None,
|
|
140
|
+
vis: dict | object = dict(
|
|
141
|
+
type='MMVisualizer',
|
|
142
|
+
window_name='Multimodal Viewer',
|
|
143
|
+
background_color=np.zeros(3),
|
|
144
|
+
point_size=1,
|
|
145
|
+
layout=[[-1]]),
|
|
146
|
+
show: bool = True,
|
|
147
|
+
**kwargs,
|
|
148
|
+
):
|
|
149
|
+
import open3d as o3d
|
|
150
|
+
|
|
151
|
+
from .visualizer import VISUALIZERS
|
|
152
|
+
|
|
153
|
+
if show and isinstance(vis, dict):
|
|
154
|
+
vis = VISUALIZERS[vis.pop('type')]().create_window(**vis)
|
|
155
|
+
|
|
156
|
+
if path is not None:
|
|
157
|
+
data = read_pickle(path)
|
|
158
|
+
kwargs.update(data)
|
|
159
|
+
|
|
160
|
+
draw_cloud(**kwargs, vis=vis, show=False)
|
|
161
|
+
draw_voxel(**kwargs, vis=vis, show=False)
|
|
162
|
+
draw_images(**kwargs, vis=vis, show=False)
|
|
163
|
+
|
|
164
|
+
if kwargs.get('points') is not None or kwargs.get('voxel_centers') is not None:
|
|
165
|
+
axis_geometry = o3d.geometry.TriangleMesh.create_coordinate_frame(size=3.0, origin=[0, 0, 0])
|
|
166
|
+
vis.add_geometry(axis_geometry, name='axis')
|
|
167
|
+
|
|
168
|
+
if show:
|
|
169
|
+
vis.run()
|
|
170
|
+
vis.destroy_window()
|
|
171
|
+
|
|
172
|
+
@rpc_func
|
|
173
|
+
def play(
|
|
174
|
+
root: str,
|
|
175
|
+
player: dict = dict(
|
|
176
|
+
type='StepPlayer',
|
|
177
|
+
start=0,
|
|
178
|
+
step=10),
|
|
179
|
+
vis: dict | object = dict(
|
|
180
|
+
type='MMVisualizer',
|
|
181
|
+
window_name='Multimodal Player',
|
|
182
|
+
background_color=np.zeros(3),
|
|
183
|
+
point_size=1,
|
|
184
|
+
layout=[[-1]]),
|
|
185
|
+
):
|
|
186
|
+
from functools import partial
|
|
187
|
+
from glob import glob
|
|
188
|
+
|
|
189
|
+
from .player import PLAYERS
|
|
190
|
+
from .visualizer import VISUALIZERS
|
|
191
|
+
|
|
192
|
+
paths = sorted(glob(f'{root}/*'))
|
|
193
|
+
def switch_callback(vis, i):
|
|
194
|
+
print(f'frame {i}: {paths[i]}')
|
|
195
|
+
|
|
196
|
+
vis.save_camera_params()
|
|
197
|
+
vis.clear_geometries()
|
|
198
|
+
|
|
199
|
+
data = read_pickle(paths[i])
|
|
200
|
+
draw(**data, vis=vis, show=False)
|
|
201
|
+
|
|
202
|
+
vis.restore_camera_params()
|
|
203
|
+
|
|
204
|
+
vis = VISUALIZERS[vis.pop('type')]().create_window(**vis)
|
|
205
|
+
player = PLAYERS[player.pop('type')](partial(switch_callback, vis), length=len(paths), **player)
|
|
206
|
+
|
|
207
|
+
vis.register_key_callback('W', player.prev_n)
|
|
208
|
+
vis.register_key_callback('S', player.next_n)
|
|
209
|
+
vis.register_key_callback('A', player.prev)
|
|
210
|
+
vis.register_key_callback('D', player.next)
|
|
211
|
+
|
|
212
|
+
player.start()
|
|
213
|
+
vis.run()
|
|
214
|
+
vis.destroy_window()
|
|
215
|
+
|
|
216
|
+
DRAW_RPC_FUNCS = {
|
|
217
|
+
'draw_cloud': draw_cloud,
|
|
218
|
+
'draw_voxel': draw_voxel,
|
|
219
|
+
'draw_images': draw_images,
|
|
220
|
+
'draw': draw,
|
|
221
|
+
'play': play,
|
|
222
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright (c) castle945. All rights reserved.
|
|
2
|
+
|
|
3
|
+
class StepPlayer:
|
|
4
|
+
|
|
5
|
+
def __init__(self, switch_callback, start, step, length):
|
|
6
|
+
self.switch_callback = switch_callback
|
|
7
|
+
self.idx = start
|
|
8
|
+
self.step = step
|
|
9
|
+
self.length = length
|
|
10
|
+
|
|
11
|
+
def prev(self):
|
|
12
|
+
self.idx = max(self.idx - 1, 0)
|
|
13
|
+
self.switch_callback(self.idx)
|
|
14
|
+
def next(self):
|
|
15
|
+
self.idx = min(self.idx + 1, self.length - 1)
|
|
16
|
+
self.switch_callback(self.idx)
|
|
17
|
+
def prev_n(self):
|
|
18
|
+
self.idx = max(self.idx - self.step, 0)
|
|
19
|
+
self.switch_callback(self.idx)
|
|
20
|
+
def next_n(self):
|
|
21
|
+
self.idx = min(self.idx + self.step, self.length - 1)
|
|
22
|
+
self.switch_callback(self.idx)
|
|
23
|
+
|
|
24
|
+
def start(self):
|
|
25
|
+
self.switch_callback(self.idx)
|
|
26
|
+
|
|
27
|
+
PLAYERS = {
|
|
28
|
+
'StepPlayer': StepPlayer,
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
|
|
3
|
+
import rpyc
|
|
4
|
+
from rpyc.utils.server import ThreadedServer
|
|
5
|
+
|
|
6
|
+
from .config import rpc_server_port
|
|
7
|
+
from .draw import DRAW_RPC_FUNCS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RPCServer:
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def start(cls):
|
|
14
|
+
class RPCService(rpyc.Service):
|
|
15
|
+
def __init__(self):
|
|
16
|
+
super().__init__()
|
|
17
|
+
self.func_map = dict()
|
|
18
|
+
self.func_map.update(DRAW_RPC_FUNCS)
|
|
19
|
+
for name, func in self.func_map.items():
|
|
20
|
+
setattr(self.__class__, f'exposed_{name}', self._create_exposed_method(name, func))
|
|
21
|
+
|
|
22
|
+
def _create_exposed_method(self, name, func):
|
|
23
|
+
def exposed_method(self, serialized_args, serialized_kwargs):
|
|
24
|
+
args, kwargs = pickle.loads(serialized_args), pickle.loads(serialized_kwargs)
|
|
25
|
+
return pickle.dumps(func(*args, **kwargs))
|
|
26
|
+
exposed_method.__name__ = f'exposed_{name}'
|
|
27
|
+
return exposed_method
|
|
28
|
+
|
|
29
|
+
server = ThreadedServer(RPCService, port=rpc_server_port, auto_register=True)
|
|
30
|
+
server.start()
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import open3d as o3d
|
|
3
|
+
from open3d.visualization import gui, rendering
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def create_grid_layout(grid2d: list[list[int]]):
|
|
7
|
+
grid2d = np.array(grid2d)
|
|
8
|
+
assert len(grid2d.shape) == 2
|
|
9
|
+
|
|
10
|
+
h, w = grid2d.shape
|
|
11
|
+
grid_h, grid_w = 1. / h, 1. / w
|
|
12
|
+
widgetIds = set(np.unique(grid2d[grid2d >= 0]))
|
|
13
|
+
layout = dict()
|
|
14
|
+
for widgetId in widgetIds:
|
|
15
|
+
positions = np.argwhere(grid2d == widgetId)
|
|
16
|
+
min_y, max_y = positions[:, 0].min(), positions[:, 0].max()
|
|
17
|
+
min_x, max_x = positions[:, 1].min(), positions[:, 1].max()
|
|
18
|
+
assert len(positions) == (max_y - min_y + 1) * (max_x - min_x + 1)
|
|
19
|
+
layout[widgetId] = (min_x * grid_w, min_y * grid_h, (max_x - min_x + 1) * grid_w, (max_y - min_y + 1) * grid_h)
|
|
20
|
+
return layout
|
|
21
|
+
|
|
22
|
+
class Visualizer:
|
|
23
|
+
def __init__(self):
|
|
24
|
+
self.vis = o3d.visualization.VisualizerWithKeyCallback()
|
|
25
|
+
self.camera_params = None
|
|
26
|
+
|
|
27
|
+
def create_window(
|
|
28
|
+
self,
|
|
29
|
+
window_name: str = 'Open3D',
|
|
30
|
+
width: int = 1920,
|
|
31
|
+
height: int = 1080,
|
|
32
|
+
background_color: np.ndarray = np.zeros(3),
|
|
33
|
+
point_size: int = 1,
|
|
34
|
+
**kwargs,
|
|
35
|
+
):
|
|
36
|
+
self.vis.create_window(window_name, width, height)
|
|
37
|
+
self.vis.get_render_option().background_color = background_color
|
|
38
|
+
self.vis.get_render_option().point_size = point_size
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def add_geometry(self, geometry, **kwargs):
|
|
42
|
+
self.vis.add_geometry(geometry)
|
|
43
|
+
|
|
44
|
+
def clear_geometries(self):
|
|
45
|
+
self.vis.clear_geometries()
|
|
46
|
+
|
|
47
|
+
def run(self):
|
|
48
|
+
self.vis.run()
|
|
49
|
+
|
|
50
|
+
def destroy_window(self):
|
|
51
|
+
self.vis.destroy_window()
|
|
52
|
+
|
|
53
|
+
def register_key_callback(self, key: str, callback: callable):
|
|
54
|
+
self.vis.register_key_callback(ord(key), lambda vis: callback())
|
|
55
|
+
|
|
56
|
+
def save_camera_params(self):
|
|
57
|
+
if self.camera_params is not None:
|
|
58
|
+
self.camera_params = self.vis.get_view_control().convert_to_pinhole_camera_parameters()
|
|
59
|
+
|
|
60
|
+
def restore_camera_params(self):
|
|
61
|
+
if self.camera_params is None:
|
|
62
|
+
self.camera_params = self.vis.get_view_control().convert_to_pinhole_camera_parameters()
|
|
63
|
+
self.vis.get_view_control().convert_from_pinhole_camera_parameters(self.camera_params, allow_arbitrary=True)
|
|
64
|
+
self.vis.update_renderer()
|
|
65
|
+
|
|
66
|
+
class MMVisualizer:
|
|
67
|
+
|
|
68
|
+
def __init__(self):
|
|
69
|
+
self.default_material = rendering.MaterialRecord()
|
|
70
|
+
self.camera_params = None
|
|
71
|
+
self.key_callbacks = dict()
|
|
72
|
+
|
|
73
|
+
def on_layout(self, layout_context):
|
|
74
|
+
R = self.window.content_rect
|
|
75
|
+
offx, offy, content_width, content_height = R.x, R.y, R.width, R.height
|
|
76
|
+
if self.widget3d:
|
|
77
|
+
relx, rely, relw, relh = self.layout[0]
|
|
78
|
+
x = int(offx + relx * content_width)
|
|
79
|
+
y = int(offy + rely * content_height)
|
|
80
|
+
widget_width = int(relw * content_width)
|
|
81
|
+
widget_height = int(relh * content_height)
|
|
82
|
+
self.widget3d.frame = gui.Rect(x, y, widget_width, widget_height)
|
|
83
|
+
|
|
84
|
+
for widgetId, widget in self.widgets2d.items():
|
|
85
|
+
relx, rely, relw, relh = self.layout[widgetId]
|
|
86
|
+
x = int(offx + relx * content_width)
|
|
87
|
+
y = int(offy + rely * content_height)
|
|
88
|
+
widget_width = int(relw * content_width)
|
|
89
|
+
widget_height = int(relh * content_height)
|
|
90
|
+
widget.frame = gui.Rect(x, y, widget_width, widget_height)
|
|
91
|
+
|
|
92
|
+
def on_key(self, event):
|
|
93
|
+
if event.type == gui.KeyEvent.Type.DOWN:
|
|
94
|
+
for key, callback in self.key_callbacks.items():
|
|
95
|
+
if event.key == key:
|
|
96
|
+
callback()
|
|
97
|
+
return True
|
|
98
|
+
|
|
99
|
+
if self.widget3d and (event.key == gui.KeyName.MINUS or event.key == gui.KeyName.EQUALS):
|
|
100
|
+
point_size = int(self.default_material.point_size / self.window.scaling)
|
|
101
|
+
if event.key == gui.KeyName.MINUS:
|
|
102
|
+
self.default_material.point_size = max(point_size - 1, 0) * self.window.scaling
|
|
103
|
+
elif event.key == gui.KeyName.EQUALS:
|
|
104
|
+
self.default_material.point_size = (point_size + 1) * self.window.scaling
|
|
105
|
+
self.widget3d.scene.update_material(self.default_material)
|
|
106
|
+
return False
|
|
107
|
+
|
|
108
|
+
def create_window(
|
|
109
|
+
self,
|
|
110
|
+
window_name: str = 'Open3D',
|
|
111
|
+
width: int = 1920,
|
|
112
|
+
height: int = 1080,
|
|
113
|
+
background_color: np.ndarray = np.zeros(4),
|
|
114
|
+
point_size: int = 1,
|
|
115
|
+
layout: list = [[-1]],
|
|
116
|
+
**kwargs,
|
|
117
|
+
):
|
|
118
|
+
self.app = gui.Application.instance
|
|
119
|
+
self.app.initialize()
|
|
120
|
+
self.window = self.app.create_window(window_name, width, height)
|
|
121
|
+
|
|
122
|
+
self.widget3d = None
|
|
123
|
+
self.widgets2d = dict()
|
|
124
|
+
self.layout = create_grid_layout(layout)
|
|
125
|
+
for widgetId in self.layout.keys():
|
|
126
|
+
if widgetId == 0:
|
|
127
|
+
widget3d = gui.SceneWidget()
|
|
128
|
+
widget3d.scene = rendering.Open3DScene(self.window.renderer)
|
|
129
|
+
self.window.add_child(widget3d)
|
|
130
|
+
self.widget3d = widget3d
|
|
131
|
+
elif widgetId > 0:
|
|
132
|
+
widget2d = gui.ImageWidget()
|
|
133
|
+
self.window.add_child(widget2d)
|
|
134
|
+
self.widgets2d[widgetId] = widget2d
|
|
135
|
+
|
|
136
|
+
self.window.set_on_layout(self.on_layout)
|
|
137
|
+
self.window.set_on_key(self.on_key)
|
|
138
|
+
|
|
139
|
+
if self.widget3d:
|
|
140
|
+
background_color = np.append(background_color, 1.0) if len(background_color) == 3 else background_color
|
|
141
|
+
self.widget3d.scene.set_background(background_color)
|
|
142
|
+
self.default_material.point_size = point_size * self.window.scaling
|
|
143
|
+
return self
|
|
144
|
+
|
|
145
|
+
def add_geometry(
|
|
146
|
+
self,
|
|
147
|
+
geometry: object,
|
|
148
|
+
name: str,
|
|
149
|
+
reset_bounding_box: bool = True,
|
|
150
|
+
):
|
|
151
|
+
self.widget3d.scene.add_geometry(name, geometry, self.default_material)
|
|
152
|
+
|
|
153
|
+
if reset_bounding_box:
|
|
154
|
+
bounds = self.widget3d.scene.bounding_box
|
|
155
|
+
center_of_rotation = bounds.get_center()
|
|
156
|
+
extent = bounds.get_extent()
|
|
157
|
+
distance = max(np.linalg.norm(extent) * 2.5 / np.sqrt(3), 0.001)
|
|
158
|
+
fov = 60
|
|
159
|
+
self.widget3d.setup_camera(fov, bounds, center_of_rotation)
|
|
160
|
+
self.widget3d.look_at(center_of_rotation, center_of_rotation + [0, 0, distance], [0, -1, 0])
|
|
161
|
+
|
|
162
|
+
def update_image(self, image: np.ndarray | o3d.geometry.Image, widgetId: int = 1):
|
|
163
|
+
assert widgetId > 0
|
|
164
|
+
if isinstance(image, np.ndarray):
|
|
165
|
+
image = o3d.geometry.Image(image)
|
|
166
|
+
self.widgets2d[widgetId].update_image(image)
|
|
167
|
+
|
|
168
|
+
def clear_geometries(self):
|
|
169
|
+
if self.widget3d:
|
|
170
|
+
self.widget3d.scene.clear_geometry()
|
|
171
|
+
|
|
172
|
+
def run(self):
|
|
173
|
+
self.app.run()
|
|
174
|
+
|
|
175
|
+
def destroy_window(self):
|
|
176
|
+
self.window.close()
|
|
177
|
+
|
|
178
|
+
def register_key_callback(self, key: str, callback: callable):
|
|
179
|
+
key = getattr(gui.KeyName, key)
|
|
180
|
+
self.key_callbacks[key] = callback
|
|
181
|
+
|
|
182
|
+
def save_camera_params(self):
|
|
183
|
+
if self.widget3d:
|
|
184
|
+
camera = self.widget3d.scene.camera
|
|
185
|
+
self.camera_params = dict(
|
|
186
|
+
model_matrix=camera.get_model_matrix(),
|
|
187
|
+
fov=camera.get_field_of_view(),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def restore_camera_params(self):
|
|
191
|
+
if self.widget3d and self.camera_params:
|
|
192
|
+
mat = self.camera_params['model_matrix']
|
|
193
|
+
eye = mat[:3, 3]
|
|
194
|
+
forward = -mat[:3, 2]
|
|
195
|
+
up = mat[:3, 1]
|
|
196
|
+
center = eye + forward
|
|
197
|
+
self.widget3d.look_at(center, eye, up)
|
|
198
|
+
|
|
199
|
+
VISUALIZERS = {
|
|
200
|
+
'Visualizer': Visualizer,
|
|
201
|
+
'MMVisualizer': MMVisualizer,
|
|
202
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: o3dvis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: open3d visualization toolkit
|
|
5
|
+
Home-page: https://github.com/castle945
|
|
6
|
+
Author: castle945
|
|
7
|
+
Author-email: castle945@njust.edu.cn
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: rpyc
|
|
10
|
+
Requires-Dist: pillow
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: summary
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
setup.py
|
|
3
|
+
o3dvis/__init__.py
|
|
4
|
+
o3dvis/config.py
|
|
5
|
+
o3dvis/draw.py
|
|
6
|
+
o3dvis/player.py
|
|
7
|
+
o3dvis/server.py
|
|
8
|
+
o3dvis/visualizer.py
|
|
9
|
+
o3dvis.egg-info/PKG-INFO
|
|
10
|
+
o3dvis.egg-info/SOURCES.txt
|
|
11
|
+
o3dvis.egg-info/dependency_links.txt
|
|
12
|
+
o3dvis.egg-info/requires.txt
|
|
13
|
+
o3dvis.egg-info/top_level.txt
|
|
14
|
+
tests/test_draw.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
o3dvis
|
o3dvis-0.1.0/setup.cfg
ADDED
o3dvis-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright (c) castle945. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from setuptools import setup
|
|
16
|
+
|
|
17
|
+
setup(
|
|
18
|
+
name='o3dvis',
|
|
19
|
+
version='0.1.0',
|
|
20
|
+
packages=['o3dvis'],
|
|
21
|
+
author='castle945',
|
|
22
|
+
author_email='castle945@njust.edu.cn',
|
|
23
|
+
url='https://github.com/castle945',
|
|
24
|
+
description='open3d visualization toolkit',
|
|
25
|
+
install_requires=[
|
|
26
|
+
'rpyc',
|
|
27
|
+
'pillow',
|
|
28
|
+
],
|
|
29
|
+
)
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
import o3dvis
|
|
5
|
+
|
|
6
|
+
NUS_ROOT = '/datasets/nuScenes'
|
|
7
|
+
|
|
8
|
+
def _generate_vis_data():
|
|
9
|
+
# mini_nuscenes_infos_val.pkl sample_idx=0 token=3e8750f331d7499e9b5123e9eb70f2e2
|
|
10
|
+
images = [
|
|
11
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_FRONT/n008-2018-08-01-15-16-36-0400__CAM_FRONT__1533151603512404.jpg'),
|
|
12
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_FRONT_RIGHT/n008-2018-08-01-15-16-36-0400__CAM_FRONT_RIGHT__1533151603520482.jpg'),
|
|
13
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_FRONT_LEFT/n008-2018-08-01-15-16-36-0400__CAM_FRONT_LEFT__1533151603504799.jpg'),
|
|
14
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_BACK/n008-2018-08-01-15-16-36-0400__CAM_BACK__1533151603537558.jpg'),
|
|
15
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_BACK_LEFT/n008-2018-08-01-15-16-36-0400__CAM_BACK_LEFT__1533151603547405.jpg'),
|
|
16
|
+
dict(path=f'{NUS_ROOT}/samples/CAM_BACK_RIGHT/n008-2018-08-01-15-16-36-0400__CAM_BACK_RIGHT__1533151603528113.jpg'),
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
points = dict(
|
|
20
|
+
path=f'{NUS_ROOT}/samples/LIDAR_TOP/n008-2018-08-01-15-16-36-0400__LIDAR_TOP__1533151603547590.pcd.bin',
|
|
21
|
+
num_features=5)
|
|
22
|
+
|
|
23
|
+
pts_semantic_mask_path = f'{NUS_ROOT}/lidarseg/v1.0-mini/fdddd75ee1d94f14a09991988dab8b3e_lidarseg.bin'
|
|
24
|
+
label_mapping = dict([
|
|
25
|
+
(1, 0), (5, 0), (7, 0), (8, 0), (10, 0), (11, 0), (13, 0),
|
|
26
|
+
(19, 0), (20, 0), (0, 0), (29, 0), (31, 0), (9, 1), (14, 2),
|
|
27
|
+
(15, 3), (16, 3), (17, 4), (18, 5), (21, 6), (2, 7), (3, 7),
|
|
28
|
+
(4, 7), (6, 7), (12, 8), (22, 9), (23, 10), (24, 11), (25, 12),
|
|
29
|
+
(26, 13), (27, 14), (28, 15), (30, 16)])
|
|
30
|
+
point_colormap = [
|
|
31
|
+
[0 , 0 , 0 ], # 0 others 通用障碍 黑色
|
|
32
|
+
[0 , 0 , 255], # 1 barrier 围挡障碍 蓝色
|
|
33
|
+
[174, 112, 0 ], # 2 bicycle 自行车 棕黄
|
|
34
|
+
[255, 180, 170], # 3 bus 公交车 粉红
|
|
35
|
+
[255, 128, 0 ], # 4 car 汽车 橙色
|
|
36
|
+
[255, 0 , 0 ], # 5 construction_vehicle 建筑车辆吊车 红色
|
|
37
|
+
[163, 217, 0 ], # 6 motorcycle 摩托车 葱黄
|
|
38
|
+
[255, 255, 0 ], # 7 pedestrian 行人 黄色
|
|
39
|
+
[6 , 82 , 121], # 8 traffic_cone 交通锥 靛蓝
|
|
40
|
+
[255, 0 , 150], # 9 trailer 拖车 洋红
|
|
41
|
+
[160, 0 , 0 ], # 10 trunk 卡车 暗红
|
|
42
|
+
[0 , 255, 255], # 11 driveable_surface 路面 靛色
|
|
43
|
+
[100, 100, 100], # 12 other_flat 道中屏障 深灰
|
|
44
|
+
[255, 180, 255], # 13 sidewalk 人行道 浅浅紫
|
|
45
|
+
[255, 100, 255], # 14 terrain 地形即人行道外的路面 浅紫
|
|
46
|
+
[200, 200, 200], # 15 manmade 人造建筑如墙等 浅灰
|
|
47
|
+
[0 , 180, 0 ], # 16 vegetation 植被 绿色
|
|
48
|
+
]
|
|
49
|
+
point_labels = np.fromfile(pts_semantic_mask_path, dtype=np.uint8)
|
|
50
|
+
point_labels = np.vectorize(label_mapping.__getitem__, otypes=[np.int64])(point_labels)
|
|
51
|
+
|
|
52
|
+
# instances = mini_nuscenes_infos_val["data_list"][0]["instances"]
|
|
53
|
+
# instances = [inst for inst in instances if inst["num_lidar_pts"] > 0]
|
|
54
|
+
# [inst["bbox_3d"][:7] for inst in instances] [inst["bbox_label_3d"] for inst in instances]
|
|
55
|
+
first6_bboxes3d = np.array([
|
|
56
|
+
[ -7.96, 36.90, 0.21, 0.65, 0.62, 1.78, -1.78],
|
|
57
|
+
[ 7.39, 17.46, -0.18, 0.94, 0.69, 1.90, -1.80],
|
|
58
|
+
[-10.37, 14.92, -0.54, 0.61, 0.58, 1.75, -1.53],
|
|
59
|
+
[-40.42, 17.11, -1.19, 1.11, 0.91, 2.00, -3.14],
|
|
60
|
+
[ 9.88, 29.82, 0.11, 1.03, 0.75, 1.98, -1.73],
|
|
61
|
+
[ 6.62, 42.97, 0.61, 4.73, 2.00, 1.48, 1.18],])
|
|
62
|
+
first6_bboxes3d_labels = np.array([7, 7, 7, 7, 7, 0])
|
|
63
|
+
det24cls_colormap = [
|
|
64
|
+
[1.0, 0.0, 0.0], # 红
|
|
65
|
+
[1.0, 0.5, 0.0], # 橙
|
|
66
|
+
[1.0, 1.0, 0.0], # 黄
|
|
67
|
+
[0.0, 0.0, 1.0], # 蓝
|
|
68
|
+
[0.0, 1.0, 1.0], # 靛
|
|
69
|
+
[1.0, 0.0, 1.0], # 紫
|
|
70
|
+
[1.0, 1.0, 0.5],
|
|
71
|
+
[1.0, 0.5, 1.0],
|
|
72
|
+
[1.0, 0.5, 0.5],
|
|
73
|
+
[1.0, 0.0, 0.5],
|
|
74
|
+
[0.5, 1.0, 1.0],
|
|
75
|
+
[0.5, 1.0, 0.5],
|
|
76
|
+
[0.5, 1.0, 0.0],
|
|
77
|
+
[0.5, 0.5, 1.0],
|
|
78
|
+
[0.5, 0.5, 0.5],
|
|
79
|
+
[0.5, 0.5, 0.0],
|
|
80
|
+
[0.5, 0.0, 1.0],
|
|
81
|
+
[0.5, 0.0, 0.5],
|
|
82
|
+
[0.5, 0.0, 0.0],
|
|
83
|
+
[0.0, 1.0, 0.5],
|
|
84
|
+
[0.0, 0.5, 1.0],
|
|
85
|
+
[0.0, 0.5, 0.5],
|
|
86
|
+
[0.0, 0.5, 0.0],
|
|
87
|
+
[0.0, 0.0, 0.5],
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
voxel_semantic_mask_path = f'{NUS_ROOT}/surroundocc/samples/n008-2018-08-01-15-16-36-0400__LIDAR_TOP__1533151603547590.pcd.bin.npy'
|
|
91
|
+
point_cloud_range = np.array([-50.0, -50.0, -5.0, 50.0, 50.0, 3.0])
|
|
92
|
+
voxel_size = [0.5, 0.5, 0.5]
|
|
93
|
+
sparse_labels = np.load(voxel_semantic_mask_path)
|
|
94
|
+
voxel_centers = np.vstack((sparse_labels[:, 0], sparse_labels[:, 1], sparse_labels[:, 2])).T * voxel_size
|
|
95
|
+
voxel_centers = voxel_centers + point_cloud_range[0:3]
|
|
96
|
+
voxel_semantics = sparse_labels[:, 3]
|
|
97
|
+
|
|
98
|
+
return dict(
|
|
99
|
+
images=images,
|
|
100
|
+
points=points,
|
|
101
|
+
point_type='XYZIR',
|
|
102
|
+
point_labels=point_labels,
|
|
103
|
+
point_colormap=point_colormap,
|
|
104
|
+
bboxes3d=first6_bboxes3d,
|
|
105
|
+
bboxes3d_labels=first6_bboxes3d_labels,
|
|
106
|
+
bboxes3d_colormap=det24cls_colormap,
|
|
107
|
+
voxel_centers=voxel_centers,
|
|
108
|
+
voxel_size=voxel_size,
|
|
109
|
+
voxel_semantics=voxel_semantics,
|
|
110
|
+
voxel_colormap=point_colormap,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
data = _generate_vis_data()
|
|
114
|
+
|
|
115
|
+
def test_draw_images():
|
|
116
|
+
o3dvis.draw_images(
|
|
117
|
+
images=data['images'],
|
|
118
|
+
vis=dict(
|
|
119
|
+
type='MMVisualizer',
|
|
120
|
+
window_name='Image Viewer',
|
|
121
|
+
background_color=np.zeros(3),
|
|
122
|
+
layout=[[3, 1, 2], [5, 4, 6]],
|
|
123
|
+
),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def test_draw_cloud():
|
|
127
|
+
o3dvis.draw_cloud(
|
|
128
|
+
points=data['points'],
|
|
129
|
+
point_type=data['point_type'],
|
|
130
|
+
# point_colormap=[[255, 255, 255]],
|
|
131
|
+
# rpc=True,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def test_draw_cloud_seg3d():
|
|
135
|
+
o3dvis.draw_cloud(
|
|
136
|
+
points=data['points'],
|
|
137
|
+
point_type=data['point_type'],
|
|
138
|
+
point_labels=data['point_labels'],
|
|
139
|
+
point_colormap=data['point_colormap'],
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def test_draw_cloud_pcdet():
|
|
143
|
+
o3dvis.draw_cloud(
|
|
144
|
+
points=data['points'],
|
|
145
|
+
point_type=data['point_type'],
|
|
146
|
+
bboxes3d=data['bboxes3d'],
|
|
147
|
+
bboxes3d_labels=data['bboxes3d_labels'],
|
|
148
|
+
bboxes3d_colormap=data['bboxes3d_colormap'],
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def test_draw_mvxdet():
|
|
152
|
+
o3dvis.draw(
|
|
153
|
+
points=data['points'],
|
|
154
|
+
point_type=data['point_type'],
|
|
155
|
+
bboxes3d=data['bboxes3d'],
|
|
156
|
+
bboxes3d_labels=data['bboxes3d_labels'],
|
|
157
|
+
bboxes3d_colormap=data['bboxes3d_colormap'],
|
|
158
|
+
images=data['images'],
|
|
159
|
+
vis=dict(
|
|
160
|
+
type='MMVisualizer',
|
|
161
|
+
window_name='Multimodal 3D Detection Viewer',
|
|
162
|
+
background_color=np.zeros(4),
|
|
163
|
+
layout=[[3, 1, 2], [0, 0, 0], [0, 0, 0], [0, 0, 0], [5, 4, 6]],
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
def test_draw_voxel():
|
|
168
|
+
o3dvis.draw_voxel(
|
|
169
|
+
voxel_centers=data['voxel_centers'],
|
|
170
|
+
voxel_size=data['voxel_size'],
|
|
171
|
+
voxel_semantics=data['voxel_semantics'],
|
|
172
|
+
voxel_colormap=data['voxel_colormap'],
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def test_draw_mvocc():
|
|
176
|
+
o3dvis.draw(
|
|
177
|
+
voxel_centers=data['voxel_centers'],
|
|
178
|
+
voxel_size=data['voxel_size'],
|
|
179
|
+
voxel_semantics=data['voxel_semantics'],
|
|
180
|
+
voxel_colormap=data['voxel_colormap'],
|
|
181
|
+
images=data['images'],
|
|
182
|
+
vis=dict(
|
|
183
|
+
type='MMVisualizer',
|
|
184
|
+
window_name='Multimodal 3D Occupancy Viewer',
|
|
185
|
+
background_color=np.ones(4),
|
|
186
|
+
point_size=10,
|
|
187
|
+
layout=[[3, 1, 2], [0, 0, 0], [0, 0, 0], [0, 0, 0], [5, 4, 6]],
|
|
188
|
+
),
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
@pytest.mark.skip(reason='')
|
|
192
|
+
def test_draw_file():
|
|
193
|
+
o3dvis.draw(
|
|
194
|
+
path='/workspace/codevault/Occ3D/OpenOcc3D/work_dirs/test_superocc/test_val/20261110_040635/vis_buffer/000000.pkl',
|
|
195
|
+
vis=dict(
|
|
196
|
+
type='MMVisualizer',
|
|
197
|
+
window_name='Multimodal 3D Occupancy Viewer',
|
|
198
|
+
background_color=np.ones(4),
|
|
199
|
+
point_size=10,
|
|
200
|
+
layout=[[3, 1, 2], [0, 0, 0], [0, 0, 0], [0, 0, 0], [5, 4, 6]],
|
|
201
|
+
),
|
|
202
|
+
# rpc=True,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
@pytest.mark.skip(reason='')
|
|
206
|
+
def test_play_dir():
|
|
207
|
+
o3dvis.play(
|
|
208
|
+
root='/workspace/codevault/Occ3D/OpenOcc3D/work_dirs/test_superocc/test_val/20261110_040635/vis_buffer',
|
|
209
|
+
vis=dict(
|
|
210
|
+
type='MMVisualizer',
|
|
211
|
+
window_name='Multimodal 3D Occupancy Viewer',
|
|
212
|
+
background_color=np.ones(4),
|
|
213
|
+
point_size=10,
|
|
214
|
+
layout=[[3, 1, 2], [0, 0, 0], [0, 0, 0], [0, 0, 0], [5, 4, 6]],
|
|
215
|
+
),
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
if __name__ == '__main__':
|
|
219
|
+
test_draw_file()
|