M12.3: tracker panel + apply
Tracker panel (Window > Tracker): Track Camera / Warp Stabilizer (disabled), Track Motion / Stabilize Motion, Motion Source, Current Track, Track Type, Position/Rotation/Scale, Motion Target with Edit Target..., Options... (Motion Tracker Options dialog), Analyze (1 frame back, back, forward, 1 frame forward; stop while running) with progress, Reset and Apply (Apply Dimensions dialog). Track point widgets in the viewer: feature and search regions with corner handles, attach point crosshair and track path, all draggable through track.setPoint (one undo step per drag). Automation ids for every widget; headless UI test. Tracker: featureless regions no longer drift (ties keep the prediction, only confident matches predict motion). docs/agents.md: tracking example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
243098a144
commit
e57e6a5120
+18
-5
@@ -372,7 +372,11 @@ impl PointState {
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
cands.sort_by(|a, b| b.0.total_cmp(&a.0));
|
||||
// Best score first; ties (flat or repetitive regions) go to the candidate nearest the
|
||||
// prediction so featureless areas don't drift.
|
||||
let cp = crop.to_level(predicted, top);
|
||||
let d2 = |c: &[f64; 2]| (c[0] - cp[0]).powi(2) + (c[1] - cp[1]).powi(2);
|
||||
cands.sort_by(|a, b| if (a.0 - b.0).abs() < 1e-9 { d2(&a.1).total_cmp(&d2(&b.1)) } else { b.0.total_cmp(&a.0) });
|
||||
let mut seeds: Vec<[f64; 2]> = vec![];
|
||||
for (_, c) in &cands {
|
||||
if seeds.iter().all(|q| (q[0] - c[0]).abs() > 1.5 || (q[1] - c[1]).abs() > 1.5) {
|
||||
@@ -390,12 +394,16 @@ impl PointState {
|
||||
for k in (0..top).rev() {
|
||||
c = [c[0] * 2.0, c[1] * 2.0];
|
||||
let (pl, tp) = (&crop.levels[k], &self.templates[k]);
|
||||
let mut lb = (f64::MIN, c);
|
||||
// Start from the projected match; neighbours must beat it (no drift on ties).
|
||||
let mut lb = (ncc(pl, tp, c, shape), c);
|
||||
for j in -2..=2 {
|
||||
for i in -2..=2 {
|
||||
if i == 0 && j == 0 {
|
||||
continue;
|
||||
}
|
||||
let q = [c[0] + i as f64, c[1] + j as f64];
|
||||
let v = ncc(pl, tp, q, shape);
|
||||
if v > lb.0 {
|
||||
if v > lb.0 + 1e-9 {
|
||||
lb = (v, q);
|
||||
}
|
||||
}
|
||||
@@ -405,7 +413,7 @@ impl PointState {
|
||||
if top == 0 {
|
||||
score = ncc(&crop.levels[0], &self.templates[0], c, shape);
|
||||
}
|
||||
if score > best.0 {
|
||||
if score > best.0 + 1e-9 {
|
||||
best = (score, crop.level_to_image(c, 0));
|
||||
}
|
||||
}
|
||||
@@ -428,6 +436,10 @@ impl PointState {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A featureless template can't be matched: stay put.
|
||||
if self.templates[0].ss < 1e-6 {
|
||||
(c, a) = (crop.to_level(predicted, 0), shape);
|
||||
}
|
||||
let mut conf = ncc(&crop.levels[0], &self.templates[0], c, a);
|
||||
// Keep the coarse match if refinement made it worse.
|
||||
let coarse = ncc(&crop.levels[0], &self.templates[0], c0, shape);
|
||||
@@ -451,7 +463,8 @@ impl PointState {
|
||||
ConfidenceAction::Adapt => status = Status::Adapted,
|
||||
}
|
||||
}
|
||||
self.velocity = [found[0] - prev[0], found[1] - prev[1]];
|
||||
// Only confident matches predict the next search position.
|
||||
self.velocity = if low { [0.0; 2] } else { [found[0] - prev[0], found[1] - prev[1]] };
|
||||
self.center = found;
|
||||
self.shape = a;
|
||||
if opts.adapt_every_frame || status == Status::Adapted {
|
||||
|
||||
@@ -240,3 +240,17 @@ fn performance_1080p_single_point() {
|
||||
assert!(dist(last.center, [c0[0] + 2.3 * 5.0, c0[1] + 1.1 * 5.0]) < 0.25, "{:?}", last.center);
|
||||
assert!(per < 0.1, "{per} s per frame");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn featureless_regions_stay_put() {
|
||||
let flat = Image::filled(200, 160, [0.3, 0.3, 0.3, 1.0]);
|
||||
for action in ConfidenceAction::ALL {
|
||||
let opts = TrackOptions { action, ..Default::default() };
|
||||
let mut tr = Tracker::new(opts, &[spec([100.0, 80.0], 21.0, 61.0)], &Frame::new(&flat));
|
||||
for _ in 0..10 {
|
||||
let r = tr.step(&Frame::new(&flat))[0];
|
||||
assert!(dist(r.center, [100.0, 80.0]) < 1e-9, "{action:?}: drifted to {:?}", r.center);
|
||||
assert!(r.confidence < 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user