Skip to content

Samples: Add DLPack GPU interop sample and stitching ROI masking - #231

Merged
torbsorb merged 1 commit into
masterfrom
2026-07-26-update-python-samples
Jul 29, 2026
Merged

Samples: Add DLPack GPU interop sample and stitching ROI masking#231
torbsorb merged 1 commit into
masterfrom
2026-07-26-update-python-samples

Conversation

@csu-bot-zivid

@csu-bot-zivid csu-bot-zivid commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

New sample: DLPack GPU interop

source/applications/advanced/cuda/capture_and_convert_to_dlpack_tensor_on_cuda.py
shows how to hand a Zivid DeviceArray to PyTorch on the GPU without a
CPU round-trip. Two paths are demonstrated:

  1. Recommended: torch.as_tensor(device_array, device="cuda"), which
    imports the buffer through the CUDA array interface that DeviceArray
    already implements — no pointer, shape or stride handling needed.
  2. Optional: build a DLPack capsule directly from the DeviceArray's
    device pointer, shape, strides (in elements), element data type and
    CUDA device, exposed through the standard __dlpack__ /
    __dlpack_device__ protocol and imported with torch.from_dlpack.
    Use this when your consumer expects a DLPack capsule directly. The
    DeviceArray is kept alive until the consumer releases the tensor.

Both hand-offs are verified zero-copy by comparing data pointers, and
both are scoped to the CUDA backend. The sample requires a CUDA-capable
GPU and PyTorch with CUDA support (pip install torch); PyTorch is a
third-party dependency that Zivid does not provide or support.

The README now lists the sample among the cuda samples.

Stitching GUI: region of interest masking

The stitching verification tab now has an optional Region of Interest
box for keeping background clutter out of the stitched point cloud.

  • Tick Enable ROI masking and set min/max X, Y and Z extents in mm.
  • The extents are given in the coordinate frame that stays fixed
    relative to the scanned object: the robot base frame for eye-in-hand
    and the robot flange frame for eye-to-hand. The group box title states
    which frame is currently in use.
  • Masking is applied to each capture before the hand-eye transform, both
    for captures taken in the GUI and for captures loaded from disk.
  • If the box would remove every point of a capture, that capture is
    shown unmasked and a warning asks you to adjust the extents, so you
    never end up with a silently empty view.

@csu-bot-zivid
csu-bot-zivid force-pushed the 2026-07-26-update-python-samples branch 5 times, most recently from e60d124 to 869c042 Compare July 28, 2026 20:30
New sample:
- capture_and_convert_to_dlpack_tensor_on_cuda: hand a Zivid
  DeviceArray to PyTorch on the GPU without a CPU round-trip. It
  shows two paths: torch.as_tensor through the CUDA array
  interface (the recommended one-liner), and building a DLPack
  capsule directly from the DeviceArray's device pointer, shape,
  strides and element type for consumers that expect the
  __dlpack__ protocol. Both hand-offs are verified zero-copy by
  comparing data pointers, and both are scoped to the CUDA
  backend. Requires PyTorch with CUDA support.
- The README lists the new sample among the cuda samples.

Stitching GUI region of interest:
- The stitching verification tab now has an optional Region of
  Interest box. Enable it and set min/max X, Y and Z in mm to
  keep background clutter out of the stitched point cloud.
- The extents are given in the frame that stays fixed relative
  to the scanned object: robot base frame for eye-in-hand, robot
  flange frame for eye-to-hand. The group box title states which
  frame is in use.
- Masking is applied per capture before the hand-eye transform,
  both for new captures and for captures loaded from disk.
- If the box would remove every point of a capture, the unmasked
  data is shown instead and a warning tells you to adjust the
  extents.
@torbsorb
torbsorb force-pushed the 2026-07-26-update-python-samples branch from 869c042 to 993e43d Compare July 29, 2026 06:06
@torbsorb torbsorb changed the title Samples: Automatic updates to public repository Samples: Add DLPack GPU interop sample and stitching ROI masking Jul 29, 2026
@torbsorb
torbsorb merged commit bd174a2 into master Jul 29, 2026
2 checks passed
@torbsorb
torbsorb deleted the 2026-07-26-update-python-samples branch July 29, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants