Declare tracking lost when the marker leaves the frame (#46)#47
Open
kalwalt wants to merge 1 commit into
Open
Conversation
Two coupled changes so the tracker stops emitting 'found' with a stale pose after the marker is gone: 1. Run the optical-flow + template-match path on (_isDetected || _isTracking), not only _isDetected. WebARKit resets _isDetected every frame and detects every frame, so once the marker leaves, MatchFeatures fails (_isDetected=false) and the track/validate path was skipped entirely -- loss was never evaluated. (ArtoolkitX gets this for free because its _isDetected persists and detection is guarded.) 2. Reset _valid in RunTemplateMatching's failure path. Template matching is the appearance check; on a static background optical flow keeps the points (no failure) but the marker template no longer matches, so updateTrackableHomography fails. runOpticalFlow's failure path already cleared _valid; RunTemplateMatching's did not, so isValid() stayed true and getMarker kept firing. ArtoolkitX has no _valid and treats !_isDetected && !_isTracking as not-visible (IsTrackableVisible). Fixes webarkit#46 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
Author
|
Companion integration PR (submodule bump + rebuilt artifacts + webcam-example verification): webarkit/webarkit-testing#39 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #46: after a marker is acquired,
isValid()/ thegetMarkerevent kept emitting found with a frozen pose indefinitely once the marker left the frame. Two coupled changes inWebARKitTracker.cppmake the tracker declare loss, matching the ArtoolkitX OCVT semantics.Root cause
WebARKit diverged from ArtoolkitX's tracker state machine in two ways:
_isDetectedonly. WebARKit resets_isDetected = falseevery frame and runs detection every frame, so_isDetectedmeans "matched this frame." Once the marker leaves,MatchFeaturesfails →_isDetected = false→ the optical-flow + template-match path was skipped entirely, so loss was never evaluated. (ArtoolkitX runs that path on a persistent_isDetectedwith guarded detection, so it re-validates every frame.)_validnot reset on template-match failure. Template matching is the appearance check. When the marker is replaced by a static background, optical flow keeps the points (they don't move → no failure), but the marker template no longer matches →updateTrackableHomographyfails.runOpticalFlow's failure path already cleared_valid;RunTemplateMatching's did not — soisValid()stayed true andgetMarkerkept firing.ArtoolkitX has no
_valid:IsTrackableVisible/GetTrackablePoseare gated purely on_isDetected || _isTracking, andRunTemplateMatchingfailure sets both false.Changes
resetTracking(): run the optical-flow/template-match block on_isDetected || _isTracking(was_isDetected), so a tracked-but-not-detected frame still re-validates (and fails → clears state) when the marker is gone.RunTemplateMatching()failure path: also set_valid = false(mirrorsrunOpticalFlow's failure path), so a lost marker propagates toisValid().Behavior
found, stable pose (template matching passes on the real marker; detection re-acquires every frame)._isDetected/_isTracking/_validcleared →isValid()false →not found. Content can be hidden by consumers.Testing
Verified against the live-webcam Teblid example (webarkit/webarkit-testing#37): acquiring the marker shows the AR content; removing it now flips to "Searching…" and hides the content within a frame or two; re-introducing re-acquires; no flicker while the marker is held in view.
Notes / follow-ups
TM_SQDIFF_NORMED < 0.5template threshold (a robustness layer, not needed in testing).Fixes #46
🤖 Generated with Claude Code