Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ add_holohub_application(deltacast_receiver DEPENDS

add_holohub_application(depth_anything_v2)

add_holohub_application(depth_to_point_cloud_demo DEPENDS OPERATORS depth_to_point_cloud)

add_subdirectory(distributed)

add_holohub_application(endoscopy_depth_estimation)
Expand Down
33 changes: 33 additions & 0 deletions applications/depth_to_point_cloud_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

project(depth_to_point_cloud_demo NONE)

find_package(holoscan 4.0.0 REQUIRED CONFIG
PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

if(BUILD_TESTING)
add_test(NAME depth_to_point_cloud_demo_python_test
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/depth_to_point_cloud_demo.py --frames 10
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_property(TEST depth_to_point_cloud_demo_python_test PROPERTY ENVIRONMENT
"PYTHONPATH=${GXF_LIB_DIR}/../python/lib:${CMAKE_BINARY_DIR}/python/lib")
Comment thread
snknitheesh marked this conversation as resolved.

set_tests_properties(depth_to_point_cloud_demo_python_test
PROPERTIES
PASS_REGULAR_EXPRESSION "valid="
FAIL_REGULAR_EXPRESSION "(^|[^a-z])Error;ERROR;Failed")
Comment thread
snknitheesh marked this conversation as resolved.
endif()
63 changes: 63 additions & 0 deletions applications/depth_to_point_cloud_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Depth to Point Cloud Demo

A minimal, hardware-free demo of the [`depth_to_point_cloud`](../../operators/depth_to_point_cloud)
Comment thread
snknitheesh marked this conversation as resolved.
Outdated
operator. It generates a synthetic organized depth image (a gently tilting plane) plus an aligned
RGB image entirely on the GPU, deprojects it into an organized `H x W x 3` point cloud, and reports
the valid-point count and Z range each frame. No camera or dataset is required.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a splash image for this application? It could be anything that can represent this application, such as diagram, screenshot, or any elaborated illustration. Thanks

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add it.

## Run

```bash
./holohub run depth_to_point_cloud_demo
# or directly:
python3 applications/depth_to_point_cloud_demo/depth_to_point_cloud_demo.py --frames 100
```

Expected output (per frame):

```text
[depth_to_point_cloud_demo] points=307200 valid=307200 z=[1.xxx, 2.xxx] m
```

## Pipeline

```text
SyntheticDepthGeneratorOp --depth--> DepthToPointCloudOp --point_cloud--> PointCloudStatsOp
--color-->
```

## Using a real Intel RealSense camera

Replace the synthetic generator with the [`realsense_camera`](../../operators/realsense_camera)
operator. It applies librealsense's `units_transform` internally, so `depth_buffer` is emitted as
**`GRAY32F` float32 already in meters** (in a `VideoBuffer`), and `color_buffer` as `RGBA8`. Because
the depth is metric, use `depth_scale=1.0` — **not** `0.001`; the `0.001` (uint16 millimeters) value
is only for raw `Z16` sources that have not been unit-transformed:

```python
from holohub.realsense_camera import RealsenseCameraOp

camera = RealsenseCameraOp(self, name="camera")
cloud = DepthToPointCloudOp(
self, name="point_cloud", allocator=...,
fx=fx, fy=fy, cx=cx, cy=cy, # from the camera's depth_camera_model intrinsics
depth_scale=1.0, # depth_buffer is float32 meters (units_transform applied)
depth_min=0.1, depth_max=10.0,
)
self.add_flow(camera, cloud, {("depth_buffer", "depth")})
self.add_flow(camera, cloud, {("color_buffer", "color")}) # color_channels = 4 (RGBA)
```

The camera also exposes `depth_camera_model` / `color_camera_model` outputs carrying the per-stream
intrinsics, which can drive the optional `intrinsics` input instead of static `fx/fy/cx/cy`.
Comment thread
snknitheesh marked this conversation as resolved.
Outdated

## Interactive 3D visualization

To view the cloud, replace `PointCloudStatsOp` with `HolovizOp` configured to render the
`point_cloud` tensor as 3D points (and the `colors` tensor for per-point color). Reshaping the
organized `H x W x 3` cloud to `N x 3` and dropping invalid (NaN) points first is recommended.
Comment thread
snknitheesh marked this conversation as resolved.
Outdated

## Requirements

- Holoscan SDK ≥ 4.0.0, CUDA, CuPy. Builds the `depth_to_point_cloud` operator (declared as a
dependency). Platforms: `x86_64`, `aarch64`.
166 changes: 166 additions & 0 deletions applications/depth_to_point_cloud_demo/depth_to_point_cloud_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Demo for DepthToPointCloudOp.

Generates a synthetic organized depth image (a gently tilting plane) plus an aligned RGB
image entirely on the GPU, deprojects it into an organized point cloud with
DepthToPointCloudOp, and validates the result. No camera or dataset is required, so the
app runs in CI. See README.md for wiring a real Intel RealSense camera or adding Holoviz
3D rendering.
"""

import argparse

import cupy as cp
from holoscan.conditions import CountCondition
from holoscan.core import Application, Operator, OperatorSpec
from holoscan.resources import BlockMemoryPool, CudaStreamPool, MemoryStorageType

from holohub.depth_to_point_cloud import DepthToPointCloudOp


class SyntheticDepthGeneratorOp(Operator):
"""Emit a synthetic float32 depth image (meters) and an aligned uint8 RGB image."""

def __init__(self, fragment, *args, width=640, height=480, **kwargs):
self.width = width
self.height = height
self.frame = 0
ys, xs = cp.meshgrid(
cp.arange(height, dtype=cp.float32),
cp.arange(width, dtype=cp.float32),
indexing="ij",
)
self._xs = xs
self._ys = ys
Comment thread
snknitheesh marked this conversation as resolved.
super().__init__(fragment, *args, **kwargs)

def setup(self, spec: OperatorSpec):
spec.output("depth")
spec.output("color")

def compute(self, op_input, op_output, context):
t = self.frame * 0.05
# A tilted plane in meters: ~1.0 m near the top-left, increasing across the frame,
# with a slow global oscillation so successive frames differ.
depth = (
1.0 + 0.5 * (self._xs / self.width) + 0.4 * (self._ys / self.height) + 0.3 * cp.sin(t)
).astype(cp.float32)

r = (255.0 * self._xs / self.width).astype(cp.uint8)
g = (255.0 * self._ys / self.height).astype(cp.uint8)
b = cp.full_like(r, 128)
color = cp.ascontiguousarray(cp.stack([r, g, b], axis=-1)) # HxWx3 uint8

op_output.emit({"depth": depth}, "depth")
op_output.emit({"color": color}, "color")
self.frame += 1


class PointCloudStatsOp(Operator):
"""Pull the point cloud and report valid-point count and Z range (CI-friendly sink)."""

def setup(self, spec: OperatorSpec):
spec.input("in")

def compute(self, op_input, op_output, context):
msg = op_input.receive("in")
pc = cp.asarray(msg["point_cloud"]) # HxWx3 float32
z = pc[..., 2]
valid = ~cp.isnan(z)
n_valid = int(valid.sum().get())

# The colored path is connected, so a colors tensor must accompany the cloud and
# share its H x W footprint (3 uint8 channels).
colors = cp.asarray(msg["colors"]) # HxWx3 uint8
if colors.shape[:2] != pc.shape[:2] or colors.shape[2] != 3:
raise RuntimeError(
f"colors shape {colors.shape} does not match cloud {pc.shape[:2]} x 3"
)

if n_valid:
zmin = float(z[valid].min().get())
zmax = float(z[valid].max().get())
print(
f"[depth_to_point_cloud_demo] points={pc.shape[0] * pc.shape[1]} "
f"valid={n_valid} z=[{zmin:.3f}, {zmax:.3f}] m colors={tuple(colors.shape)}"
)
else:
print("[depth_to_point_cloud_demo] no valid points")


class DepthToPointCloudDemoApp(Application):
def __init__(self, frames=100, width=640, height=480):
super().__init__()
self._frames = frames
self._width = width
self._height = height

def compose(self):
generator = SyntheticDepthGeneratorOp(
self,
CountCondition(self, count=self._frames),
name="generator",
width=self._width,
height=self._height,
)

# Two device tensors per frame (HxWx3 float32 point cloud + HxWx3 uint8 colors) drawn
# from this pool; size each block for the larger (float32 XYZ) output and keep enough
# blocks for both tensors plus one frame of pipelining headroom.
out_blocks = 4
block_size = self._width * self._height * 3 * 4 # float32 XYZ is the larger output
cloud = DepthToPointCloudOp(
self,
name="point_cloud",
allocator=BlockMemoryPool(
self,
name="pool",
storage_type=MemoryStorageType.DEVICE,
block_size=block_size,
num_blocks=out_blocks,
),
# Pinhole intrinsics for the synthetic camera (principal point at image center).
fx=float(self._width) * 0.8,
fy=float(self._width) * 0.8,
Comment thread
snknitheesh marked this conversation as resolved.
cx=(self._width - 1) / 2.0,
cy=(self._height - 1) / 2.0,
depth_scale=1.0, # synthetic depth is already in meters
depth_min=0.1,
depth_max=10.0,
cuda_stream_pool=CudaStreamPool(self, name="stream_pool", reserved_size=4),
)

sink = PointCloudStatsOp(self, name="stats")

self.add_flow(generator, cloud, {("depth", "depth")})
self.add_flow(generator, cloud, {("color", "color")})
self.add_flow(cloud, sink, {("point_cloud", "in")})


def main():
parser = argparse.ArgumentParser(description="DepthToPointCloudOp synthetic demo")
parser.add_argument("--frames", type=int, default=100, help="Number of frames to process")
parser.add_argument("--width", type=int, default=640)
parser.add_argument("--height", type=int, default=480)
args = parser.parse_args()

app = DepthToPointCloudDemoApp(frames=args.frames, width=args.width, height=args.height)
app.run()
Comment thread
coderabbitai[bot] marked this conversation as resolved.


if __name__ == "__main__":
main()
42 changes: 42 additions & 0 deletions applications/depth_to_point_cloud_demo/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "urn:holohub:application:v1",
"application": {
"name": "Depth to Point Cloud Demo",
"description": "Hardware-free demo of DepthToPointCloudOp: a synthetic GPU depth+RGB generator is deprojected into an organized point cloud and validated each frame.",
"authors": [
{
"name": "Nitheesh Kumar",
"affiliation": "Zobot Lab"
}
],
"language": "Python",
"version": "0.1.0",
"changelog": {
"0.1.0": "Initial release: synthetic depth generator -> DepthToPointCloudOp -> validation sink."
},
"holoscan_sdk": {
"minimum_required_version": "4.0.0",
"tested_versions": [
"4.3.0"
]
},
"platforms": [
"x86_64",
"aarch64"
],
"tags": ["Point Cloud", "Depth", "3D", "Robotics"],
"ranking": 3,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
"requirements": {
"python-packages": [
{
"name": "cupy",
"version": "13.6.0"
}
]
},
"run": {
"command": "python3 <holohub_app_source>/depth_to_point_cloud_demo.py",
"workdir": "holohub_bin"
Comment thread
snknitheesh marked this conversation as resolved.
Outdated
}
}
}
1 change: 1 addition & 0 deletions operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_holohub_operator(cvcuda_holoscan_interop)
add_subdirectory(deidentification)
add_subdirectory(dds)
add_holohub_operator(deltacast_videomaster)
add_holohub_operator(depth_to_point_cloud)
add_holohub_operator(display_gpu_resident)
add_holohub_operator(ucxx_send_receive)
add_holohub_operator(emergent_source DEPENDS EXTENSIONS emergent_source)
Expand Down
54 changes: 54 additions & 0 deletions operators/depth_to_point_cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.24)

project(depth_to_point_cloud LANGUAGES CXX CUDA)

find_package(holoscan 4.0.0 REQUIRED CONFIG
PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

add_library(depth_to_point_cloud SHARED
depth_to_point_cloud.cpp
depth_to_point_cloud.hpp
deproject.cu
deproject.hpp
)

set_target_properties(depth_to_point_cloud
PROPERTIES
# compile for the architecture of the current GPU
CUDA_ARCHITECTURES "native"
Comment thread
snknitheesh marked this conversation as resolved.
)

target_link_libraries(depth_to_point_cloud
PUBLIC
holoscan::core
)

target_include_directories(depth_to_point_cloud
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

if(HOLOHUB_BUILD_PYTHON)
add_subdirectory(python)
endif()

if(BUILD_TESTING)
add_subdirectory(test)
endif()

install(TARGETS depth_to_point_cloud)
Loading