Skip to content

fix: ToF example colorization flicker - #1906

Merged
CasualMathEnjoyer merged 6 commits into
developfrom
fix/tof-examples
Jul 27, 2026
Merged

fix: ToF example colorization flicker#1906
CasualMathEnjoyer merged 6 commits into
developfrom
fix/tof-examples

Conversation

@CasualMathEnjoyer

@CasualMathEnjoyer CasualMathEnjoyer commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes flickering depth colorization in the ToF examples by mapping colors from the fixed minDepth/maxDepth range instead of each frame's own min/max

Summary by CodeRabbit

  • Bug Fixes
    • Stabilized depth-to-color visualization across frames by switching to a consistent, configured logarithmic depth window (min/max) instead of per-frame scaling.
    • Preserved invalid (zero) depth pixels as black in depth visualizations.
  • New Features
    • Refreshed the ToF depth alignment/blending example with fixed log-depth mapping, command-line camera selection (left/right), separate aligned-vs-blended views, and a blend-weight trackbar.
    • Increased the default FPS to 30 across the updated ToF Python/C++ examples.

Map depth-to-color interpolation from the fixed minDepth/maxDepth log
range instead of each frame's own min/max, so a given depth always
maps to the same color instead of flickering as the per-frame range shifts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ToF examples now use fixed logarithmic minDepth/maxDepth ranges for color mapping and 30 FPS configuration. The aligned C++ example adds camera selection, host-run synchronization and alignment, and adjustable RGB/depth blending.

Changes

ToF depth visualization

Layer / File(s) Summary
Fixed log-depth color mapping
examples/python/ToF/tof_*.py, examples/cpp/ToF/tof_all_queues.cpp, examples/cpp/ToF/tof_minimal.cpp
Depth values are clipped and mapped using fixed logarithmic bounds instead of per-frame valid-pixel ranges, while invalid-depth handling remains in place.
Aligned synchronization and blending flow
examples/cpp/ToF/tof_align.cpp
The example defines fixed depth constants, selects a left or right alignment target, synchronizes RGB with aligned depth, and displays adjustable weighted depth/RGB views.
ToF rate and queue configuration
examples/python/ToF/tof_*.py, examples/cpp/ToF/tof_*.cpp
ToF examples use 30 FPS settings, explicit node configuration, and platform-specific output queues; related CLI examples and formatting are updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant tof_align
  participant Alignment
  participant Sync
  participant Windows
  User->>tof_align: Select camera and adjust RGB weight
  tof_align->>Alignment: Run host alignment
  Alignment->>Sync: Send aligned depth
  tof_align->>Sync: Send RGB
  Sync->>tof_align: Return synchronized frames
  tof_align->>Windows: Display depth and blended overlay
Loading

Possibly related PRs

Suggested reviewers: jakubfara

Poem

A rabbit hops through colors bright,
Fixed depth bounds keep hues just right.
RGB and depth now blend in view,
Invalid spots stay dark and true.
Hop, hop—ToF shines anew!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: fixing ToF example depth colorization flicker.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tof-examples

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JakubFara JakubFara left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fix also C++ examples

Comment thread examples/python/ToF/tof_align.py Outdated
Comment thread examples/python/ToF/tof_align.py
CasualMathEnjoyer and others added 2 commits July 22, 2026 17:19
Map depth-to-color interpolation from the fixed minDepth/maxDepth log
range instead of each frame's own min/max, matching the Python examples,
so a given depth always maps to the same color instead of flickering.

Also rewrites tof_align.cpp to match tof_align.py: drops the
ToFDepthConfidenceFilter block and its extra window, builds the ToF node
with CameraBoardSocket::AUTO instead of a hardcoded socket, and adds a
--camera left|right flag to pick the align target camera.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Bring all ToF examples (C++ and Python) to a consistent 30 FPS,
add RVC2/RVC4 output-queue detection to tof_all_queues.cpp to match
the Python version, and remove leftover comments/typos.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/cpp/ToF/tof_align.cpp`:
- Line 11: Align the synchronization threshold units used by the C++ tof_align
example at FPS and the Python tof_align example, using one shared millisecond or
frame-count convention so both retain the same effective margin. Update
examples/cpp/ToF/tof_align.cpp:11 and examples/python/ToF/tof_align.py:17
consistently; adjust the threshold calculations in the synchronization logic
without changing unrelated behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 19fa5544-1358-413e-b860-e40a6fed0eb1

📥 Commits

Reviewing files that changed from the base of the PR and between f8d713c and 079e80e.

📒 Files selected for processing (7)
  • examples/cpp/ToF/tof_align.cpp
  • examples/cpp/ToF/tof_all_queues.cpp
  • examples/cpp/ToF/tof_minimal.cpp
  • examples/python/ToF/tof_align.py
  • examples/python/ToF/tof_all_queues.py
  • examples/python/ToF/tof_minimal.py
  • examples/python/ToF/tof_pointcloud.py
📜 Review details
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-05-28T13:36:26.383Z
Learnt from: moratom
Repo: luxonis/depthai-core PR: 1812
File: examples/cpp/ImageManip/image_manip_remap.cpp:51-52
Timestamp: 2026-05-28T13:36:26.383Z
Learning: In depthai-core example code, do not set `ImageManip::Backend::GPU` unconditionally. The GPU backend is only available on RVC4 (not RVC2). Prefer leaving the backend as the default, or comment out the GPU backend selection and add a clear note explaining it is RVC4-only support (so the example won’t fail or mislead on RVC2).

Applied to files:

  • examples/python/ToF/tof_minimal.py
  • examples/python/ToF/tof_pointcloud.py
  • examples/cpp/ToF/tof_minimal.cpp
  • examples/cpp/ToF/tof_all_queues.cpp
  • examples/python/ToF/tof_align.py
  • examples/python/ToF/tof_all_queues.py
  • examples/cpp/ToF/tof_align.cpp
🔇 Additional comments (8)
examples/python/ToF/tof_pointcloud.py (1)

9-9: LGTM!

Also applies to: 21-21, 30-30

examples/cpp/ToF/tof_align.cpp (1)

17-43: LGTM!

Also applies to: 45-51, 53-72, 73-85, 89-103, 104-130

examples/cpp/ToF/tof_all_queues.cpp (1)

2-9: LGTM!

Also applies to: 11-37, 45-68

examples/cpp/ToF/tof_minimal.cpp (1)

6-7: LGTM!

Also applies to: 25-27, 40-45

examples/python/ToF/tof_align.py (2)

5-6: LGTM!


24-37: LGTM!

examples/python/ToF/tof_all_queues.py (1)

14-14: LGTM!

Also applies to: 17-30, 40-48, 61-62

examples/python/ToF/tof_minimal.py (1)

14-14: LGTM!

Also applies to: 17-30, 41-44

Comment thread examples/cpp/ToF/tof_align.cpp
Use double-precision seconds converted to nanoseconds instead of
truncating to whole milliseconds, matching the exact half-frame-period
margin used by the Python tof_align example.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@aljazkonec1

Copy link
Copy Markdown
Collaborator

@JakubFara up to you to confirm & merge. Thanks.

@CasualMathEnjoyer
CasualMathEnjoyer merged commit 7d26745 into develop Jul 27, 2026
1 check passed
@CasualMathEnjoyer
CasualMathEnjoyer deleted the fix/tof-examples branch July 27, 2026 10:34
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