[ITEP-81197] Publish to scene topics when there are no detections#591
[ITEP-81197] Publish to scene topics when there are no detections#591dpitulax merged 10 commits intorelease-2025.2from
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where detection objects were persisting in the scene UI when no new detections occurred. The change ensures that when a message contains no detection types, empty arrays are explicitly added for all tracked types before processing, which allows the tracker to properly clear stale detections.
- Adds logic to handle messages with no detections by populating empty arrays for all tracked detection types
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| detection_types = list(scene.tracker.trackers.keys()) | ||
| for dtype in detection_types: |
There was a problem hiding this comment.
The variable detection_types is reassigned from an empty list to a populated list, but this reassignment only affects the local scope. If detection_types is used elsewhere in the function after this block, the reassignment could lead to unexpected behavior. Consider using a different variable name (e.g., tracked_types) for the list of tracker keys to avoid confusion and maintain clarity about which detection types are being referenced.
| detection_types = list(scene.tracker.trackers.keys()) | |
| for dtype in detection_types: | |
| tracked_types = list(scene.tracker.trackers.keys()) | |
| for dtype in tracked_types: |
There was a problem hiding this comment.
Changing it this way would be confusing. detection_types can be (line 400) a reference to the dictionary keys, not a copy. Modifying jdata (referenced keys) will also modify detection_types because it's a dictionary view.
The explicit reassignment makes this side effect visible without requiring readers to understand dictionary view semantics.
rawatts10
left a comment
There was a problem hiding this comment.
Verified working, so approved. I don't really like the idea of caching past tracked_types, but because we publish per-class topics it may be necessary. We should revisit this in the future, particularly since there are other edge cases that should be considered (e.g. cameras going down -- if no frames are coming from the camera then the last detection stays in the scene). This is something we can take up with TTL and persistence on the scene.
📝 Description
ITEP-81197
Detections are no longer hanging on the scene UI and disappear as no detections occur.
✨ Type of Change
Select the type of change your PR introduces:
🧪 Testing Scenarios
Describe how the changes were tested and how reviewers can test them too:
✅ Checklist
Before submitting the PR, ensure the following: