Skip to content

Commit 222b337

Browse files
authored
new: ct.render.render_geometries as depth image (#57)
1 parent fd372f0 commit 222b337

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

camtools/render.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def render_geometries(
1414
view_status_str: str = None,
1515
height: int = 720,
1616
width: int = 1280,
17-
visible: bool = False,
1817
point_size: float = 1.0,
1918
line_radius: float = None,
19+
to_depth=False,
20+
visible: bool = False,
2021
) -> None:
2122
"""
2223
Render Open3D geometries to an image. This function may require a display.
@@ -33,15 +34,17 @@ def render_geometries(
3334
size and the point size.
3435
height: int image height.
3536
width: int image width.
36-
visible: bool whether to show the window.
3737
point_size: float point size for point cloud objects.
3838
line_radius: float line radius for line set objects, when set, the line
3939
sets will be converted to cylinder meshes with the given radius.
4040
The radius is in world metric space, not relative pixel space like
4141
the point size.
42+
to_depth: bool whether to render a depth image instead of RGB image.
43+
visible: bool whether to show the window.
4244
4345
Returns:
44-
image: (H, W, 3) float32 np.ndarray image.
46+
(H, W, 3) float32 np.ndarray RGB image by default; (H, W) float32
47+
depth image if to_depth is True.
4548
"""
4649

4750
if not isinstance(geometries, list):
@@ -100,9 +103,12 @@ def render_geometries(
100103

101104
vis.poll_events()
102105
vis.update_renderer()
103-
buffer = vis.capture_screen_float_buffer()
106+
if to_depth:
107+
buffer = vis.capture_depth_float_buffer()
108+
else:
109+
buffer = vis.capture_screen_float_buffer()
104110
vis.destroy_window()
105-
im_buffer = np.asarray(buffer)
111+
im_buffer = np.asarray(buffer).astype(np.float32)
106112

107113
return im_buffer
108114

0 commit comments

Comments
 (0)