From 439148d8e0e05d3d2848c25781b1d3896bcad131 Mon Sep 17 00:00:00 2001 From: Samantha Myers <26049947+thesammykins@users.noreply.github.com> Date: Sat, 31 Oct 2026 10:11:24 +0000 Subject: [PATCH 01/12] feat: add mask tracking markers to GPUI editor Expose existing mask keyframes through editable markers and local motion tracking. Four-point tracking combines corner patches with region matching to follow resizing content, with adjustable handles and an explicit start before writing a simplified path. Keep the project format unchanged and share interpolation between preview, export and canvas edits. Hold lost targets, flag results for review, preserve partial results on Stop, and reject stale jobs after concurrent edits. Share frame pyramids across trackers without changing their saved paths. --- apps/desktop-gpui/README.md | 2 +- .../kernels/src/four_point_track.rs | 331 +++++ apps/desktop-gpui/kernels/src/lib.rs | 2 + apps/desktop-gpui/kernels/src/motion_track.rs | 1140 +++++++++++++++++ apps/desktop-gpui/locales/de.toml | 13 +- apps/desktop-gpui/locales/en.toml | 13 +- apps/desktop-gpui/locales/es.toml | 13 +- apps/desktop-gpui/locales/fr.toml | 13 +- apps/desktop-gpui/locales/hi.toml | 13 +- apps/desktop-gpui/locales/ja.toml | 13 +- apps/desktop-gpui/locales/zh-CN.toml | 13 +- apps/desktop-gpui/src/editor_canvas.rs | 169 ++- apps/desktop-gpui/src/editor_edits.rs | 10 +- apps/desktop-gpui/src/editor_mask_tracking.rs | 327 +++++ apps/desktop-gpui/src/editor_panels.rs | 174 ++- apps/desktop-gpui/src/editor_timeline.rs | 26 +- apps/desktop-gpui/src/editor_window.rs | 35 +- .../src/i18n/editor_panels_surface_tests.rs | 24 + apps/desktop-gpui/src/main.rs | 1 + crates/export/src/preview.rs | 49 +- crates/project/src/lib.rs | 1 + crates/project/src/mask_tracking.rs | 517 ++++++++ crates/rendering/src/mask.rs | 270 +--- 23 files changed, 2855 insertions(+), 314 deletions(-) create mode 100644 apps/desktop-gpui/kernels/src/four_point_track.rs create mode 100644 apps/desktop-gpui/kernels/src/motion_track.rs create mode 100644 apps/desktop-gpui/src/editor_mask_tracking.rs create mode 100644 crates/project/src/mask_tracking.rs diff --git a/apps/desktop-gpui/README.md b/apps/desktop-gpui/README.md index 13093e19179..8e79b567c7c 100644 --- a/apps/desktop-gpui/README.md +++ b/apps/desktop-gpui/README.md @@ -2068,7 +2068,7 @@ selected", with a "Select all") because the source's does. | **zoom** | Amount slider, Auto/Manual mode tabs, the "How does it work?" reveal, and — in Manual — a `PositionPad` writing `mode.manual.{x,y}` | `ZoomMultiSegmentConfig`: shared Amount and Mode with a **Mixed** badge when the selection disagrees, one shared pad, and a removable row per segment | | **text** | multi-line content box, Enabled, Layout, **Templates** (8 preset cards), Font family / weight / italic / size, alignment, line height, letter spacing, colour, opacity, shadow, position, and in/out animations with durations | one card per segment | | **caption** | text box and Timing (Start / End `NumberField`s with a live duration) | one card per segment | -| **mask** | Sensitive / Highlight kind, Enabled, then either Effect (Blur / Pixelate) + amount, or Outside Darkness + Fade Duration | one card per segment | +| **mask** | Sensitive / Highlight kind, Enabled, then either Effect (Blur / Pixelate) + amount, or Outside Darkness + Fade Duration, then Tracking: Add / Remove Marker at the playhead, Clear, Track Motion and Four Points. Select four corners, adjust their circular handles, then start tracking; Cancel and Undo remain available during placement. Stop preserves partial tracking. Timing dots live on the timeline, not in the panel. The tracked mask remains rectangular. | one card per segment | | **scene** | Camera Layout (5 modes, two disabled without a camera), a description card, Transition In/Out, and — for Split Screen and Floating — Screen/Camera Zoom and two `PositionPad`s | header **alone**, which is the source's own unfinished state (`:1667-1678` renders the body only for a single selection) and is reproduced rather than invented over | | **3D** | **Templates** (3 scenes, 5 angle presets, 8 motion templates), the Start/End pose cards with swap and flips, Camera (9 sliders), Blur (mode, bokeh, per-mode sliders), Advanced (transitions, motion style) | header alone, same as the source | | **audio** | track card, name box, Volume, Fade In, Fade Out | one card per segment | diff --git a/apps/desktop-gpui/kernels/src/four_point_track.rs b/apps/desktop-gpui/kernels/src/four_point_track.rs new file mode 100644 index 00000000000..3dccf8d1fe8 --- /dev/null +++ b/apps/desktop-gpui/kernels/src/four_point_track.rs @@ -0,0 +1,331 @@ +use crate::motion_track::{ + BRIDGED_GAP, HOLD_LEAD, LumaFrame, MotionTracker, Pyramid, TrackPoint, TrackSession, +}; + +type Point = (f64, f64); + +pub struct FourPointSession { + region: TrackSession, + trackers: [MotionTracker; 4], + anchors: [Point; 4], + offsets: [Point; 4], + patch_size: Point, + initial_size: Point, + corners: Vec<(f64, [Point; 4])>, + unresolved: Vec, +} + +impl FourPointSession { + pub fn new(frame: &LumaFrame, time: f64, mut points: [Point; 4]) -> Option { + if points.iter().any(|&(x, y)| { + !x.is_finite() + || !y.is_finite() + || !(0.0..=1.0).contains(&x) + || !(0.0..=1.0).contains(&y) + }) { + return None; + } + points.sort_by(|a, b| a.1.total_cmp(&b.1)); + points[..2].sort_by(|a, b| a.0.total_cmp(&b.0)); + points[2..].sort_by(|a, b| b.0.total_cmp(&a.0)); + let inside = region_at(time, points)?; + let left = points.iter().map(|p| p.0).fold(f64::INFINITY, f64::min); + let top = points.iter().map(|p| p.1).fold(f64::INFINITY, f64::min); + let right = points.iter().map(|p| p.0).fold(f64::NEG_INFINITY, f64::max); + let bottom = points.iter().map(|p| p.1).fold(f64::NEG_INFINITY, f64::max); + let size = (right - left, bottom - top); + let region = TrackSession::new( + frame, + time, + ((left + right) / 2.0, (top + bottom) / 2.0), + size, + )?; + let (width, height) = (frame.width() as f64, frame.height() as f64); + let side = 16.0_f64 + .min(inside.size.0 * width / 2.0) + .min(inside.size.1 * height / 2.0) + .floor(); + if side < 8.0 { + return None; + } + let mut trackers = Vec::with_capacity(4); + let mut offsets = [(0.0, 0.0); 4]; + let anchors = points.map(|p| ((p.0 - left) / size.0, (p.1 - top) / size.1)); + for (index, point) in points.into_iter().enumerate() { + let (px, py) = (point.0 * width, point.1 * height); + let x = (px - side / 2.0).round().clamp(0.0, width - side); + let y = (py - side / 2.0).round().clamp(0.0, height - side); + offsets[index] = ((px - x) / side - 0.5, (py - y) / side - 0.5); + trackers.push(MotionTracker::new( + frame, + x as usize, + y as usize, + side as usize, + side as usize, + )?); + } + Some(Self { + region, + trackers: trackers.try_into().ok()?, + anchors, + offsets, + patch_size: (side / width, side / height), + initial_size: size, + corners: vec![(time, points)], + unresolved: Vec::new(), + }) + } + + pub fn push(&mut self, time: f64, frame: LumaFrame) { + let pyramid = Pyramid::new(&frame); + self.region.push_pyramid(time, &pyramid); + let (region, confidence) = self.region.latest(); + let (width, height) = (frame.width() as f64, frame.height() as f64); + let mut local = self.trackers.clone(); + let mut local_points = [(0.0, 0.0); 4]; + let mut complete = true; + let mut local_confidence = 1.0_f32; + for (index, tracker) in local.iter_mut().enumerate() { + if let Some(found) = tracker + .follow_only(&pyramid) + .filter(|found| found.score >= 0.65) + { + local_confidence = local_confidence.min(found.score); + let offset = self.offsets[index]; + local_points[index] = ( + (found.x + (0.5 + offset.0) * found.width) / width, + (found.y + (0.5 + offset.1) * found.height) / height, + ); + } else { + complete = false; + } + } + let follows_region = local_confidence >= 0.9 + || confidence < 0.9 + || local_points + .iter() + .zip(self.anchors) + .all(|(point, anchor)| { + let expected = project(region, anchor); + ((point.0 - expected.0) * width).hypot((point.1 - expected.1) * height) <= 8.0 + }); + if complete + && coherent(self.anchors, local_points, (width, height)) + && follows_region + && region_at(time, local_points).is_some() + { + self.trackers = local; + let points = if confidence >= 0.85 && local_confidence < confidence { + self.anchors.map(|anchor| project(region, anchor)) + } else { + local_points + }; + self.corners.push((time, points)); + return; + } + if region.time != time { + self.unresolved.push(time); + return; + } + let mut points = self.anchors.map(|anchor| project(region, anchor)); + for (index, tracker) in self.trackers.iter_mut().enumerate() { + let point = points[index]; + let offset = self.offsets[index]; + let patch = ( + self.patch_size.0 * region.size.0 / self.initial_size.0, + self.patch_size.1 * region.size.1 / self.initial_size.1, + ); + let center = ( + (point.0 - offset.0 * patch.0) * width, + (point.1 - offset.1 * patch.1) * height, + ); + if let Some(found) = tracker.track_near(&pyramid, center) + && confidence < 0.85 + { + points[index] = ( + (found.x + (0.5 + offset.0) * found.width) / width, + (found.y + (0.5 + offset.1) * found.height) / height, + ); + } + } + if region_at(time, points).is_some() { + self.corners.push((time, points)); + } + } + + pub fn finish(self) -> (Vec, Vec<(f64, f64)>) { + let (path, lost) = self.region.finish(); + let mut path = path + .into_iter() + .filter(|point| { + !lost + .iter() + .any(|(from, to)| point.time >= *from && point.time < *to) + }) + .filter_map(|point| { + region_at( + point.time, + self.anchors.map(|anchor| project(point, anchor)), + ) + }) + .collect::>(); + for (time, corners) in self.corners { + if let Some(region) = region_at(time, corners) { + let index = path.partition_point(|point| point.time < time); + if path.get(index).is_some_and(|point| point.time == time) { + path[index] = region; + } else { + path.insert(index, region); + } + } + } + for &(_, end) in &lost { + let next = path.partition_point(|point| point.time < end); + if let Some(previous) = next.checked_sub(1).map(|index| path[index]) + && end - previous.time > BRIDGED_GAP + { + path.insert( + next, + TrackPoint { + time: end - HOLD_LEAD, + ..previous + }, + ); + } + } + let lost = lost + .into_iter() + .filter(|(from, to)| { + self.unresolved + .iter() + .any(|time| time >= from && time <= to) + }) + .collect(); + (path, lost) + } +} + +fn coherent(anchors: [Point; 4], points: [Point; 4], size: Point) -> bool { + let fit = |axis: fn(Point) -> f64, pixels: f64| { + let a = anchors.map(axis); + let b = points.map(axis); + let mean_a = a.iter().sum::() / 4.0; + let mean_b = b.iter().sum::() / 4.0; + let variance = a.iter().map(|v| (v - mean_a).powi(2)).sum::(); + let slope = a + .iter() + .zip(b) + .map(|(a, b)| (a - mean_a) * (b - mean_b)) + .sum::() + / variance; + slope > 0.0 + && a.iter() + .zip(b) + .all(|(a, b)| ((b - mean_b) - slope * (a - mean_a)).abs() * pixels <= 3.0) + }; + fit(|p| p.0, size.0) && fit(|p| p.1, size.1) +} + +fn project(region: TrackPoint, anchor: Point) -> Point { + ( + region.center.0 + (anchor.0 - 0.5) * region.size.0, + region.center.1 + (anchor.1 - 0.5) * region.size.1, + ) +} + +fn region_at(time: f64, [tl, tr, br, bl]: [Point; 4]) -> Option { + let left = tl.0.max(bl.0); + let right = tr.0.min(br.0); + let top = tl.1.max(tr.1); + let bottom = bl.1.min(br.1); + if right <= left || bottom <= top { + return None; + } + Some(TrackPoint { + time, + center: ((left + right) / 2.0, (top + bottom) / 2.0), + size: (right - left, bottom - top), + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn window(step: usize) -> (LumaFrame, [Point; 4]) { + let (left, top, right, bottom) = (40 + step, 30 + step / 2, 160 + 3 * step, 130 - step); + let points = [(left, top), (right, top), (right, bottom), (left, bottom)]; + let mut rgba = vec![45u8; 320 * 180 * 4]; + for y in top..=bottom { + for x in left..=right { + let value = ((x * 17 + y * 31 + step * 73) % 180 + 60) as u8; + rgba[(y * 320 + x) * 4..(y * 320 + x) * 4 + 4] + .copy_from_slice(&[value, value, value, 255]); + } + } + for (corner, &(x, y)) in points.iter().enumerate() { + for dy in 0..16 { + for dx in 0..16 { + let value = ((dx * 37 + dy * 61 + corner * 43 + dx * dy * 19) % 220 + 20) as u8; + let offset = ((y + dy - 8) * 320 + x + dx - 8) * 4; + rgba[offset..offset + 4].copy_from_slice(&[value, value, value, 255]); + } + } + } + ( + LumaFrame::from_rgba(&rgba, 320, 180, 320 * 4), + points.map(|(x, y)| (x as f64 / 320.0, y as f64 / 180.0)), + ) + } + + #[test] + fn follows_independent_width_and_height_changes_with_changing_contents() { + let (first, points) = window(0); + let mut session = + FourPointSession::new(&first, 0.0, [points[2], points[0], points[3], points[1]]) + .unwrap(); + for step in 1..=20 { + session.push(step as f64 / 30.0, window(step).0); + } + let hidden = LumaFrame::from_rgba(&vec![0; 320 * 180 * 4], 320, 180, 320 * 4); + for step in 21..=40 { + session.push(step as f64 / 30.0, hidden.clone()); + } + let (path, _) = session.finish(); + for step in 0..=20 { + let time = step as f64 / 30.0; + let found = path + .iter() + .find(|point| point.time == time) + .expect("every frame tracked"); + let left = (40 + step) as f64; + let top = (30 + step / 2) as f64; + let right = (160 + 3 * step) as f64; + let bottom = (130 - step) as f64; + let expected = TrackPoint { + time, + center: ((left + right) / 640.0, (top + bottom) / 360.0), + size: ((right - left) / 320.0, (bottom - top) / 180.0), + }; + assert!( + (found.center.0 - expected.center.0).abs() * 320.0 < 2.0, + "{step}: {found:?}" + ); + assert!( + (found.center.1 - expected.center.1).abs() * 180.0 < 2.0, + "{step}: {found:?}" + ); + assert!( + (found.size.0 - expected.size.0).abs() * 320.0 < 3.0, + "{step}: {found:?}" + ); + assert!( + (found.size.1 - expected.size.1).abs() * 180.0 < 3.0, + "{step}: {found:?}" + ); + } + let last = path.last().unwrap(); + assert!((last.center.0 * 320.0 - 140.0).abs() < 2.0, "{last:?}"); + assert!((last.size.0 * 320.0 - 160.0).abs() < 3.0, "{last:?}"); + } +} diff --git a/apps/desktop-gpui/kernels/src/lib.rs b/apps/desktop-gpui/kernels/src/lib.rs index 3971ea2da35..2e37f83d3b2 100644 --- a/apps/desktop-gpui/kernels/src/lib.rs +++ b/apps/desktop-gpui/kernels/src/lib.rs @@ -1,6 +1,8 @@ pub mod codec; +pub mod four_point_track; pub mod frame; pub mod mask_cache; +pub mod motion_track; pub mod png; pub mod screenshot; pub mod texture; diff --git a/apps/desktop-gpui/kernels/src/motion_track.rs b/apps/desktop-gpui/kernels/src/motion_track.rs new file mode 100644 index 00000000000..f5b7d9b96b9 --- /dev/null +++ b/apps/desktop-gpui/kernels/src/motion_track.rs @@ -0,0 +1,1140 @@ +//! Template tracking by weighted zero-mean normalized cross-correlation (the +//! method OpenCV calls `TM_CCOEFF_NORMED` with a mask), searched coarse to +//! fine over a 2x pyramid. The weights taper towards the box edges, so a box +//! drawn loosely around a target follows the target rather than the +//! background around it. Each frame also tries a few nearby scales, so a box +//! follows content that zooms; partial matches at the frame edge keep a +//! target that is leaving the frame covered until it is gone. + +const MAX_LEVELS: usize = 4; +const MIN_COARSE_SIDE: usize = 12; +const MIN_REACQUIRE_SIDE: usize = 6; +const REACQUIRE_EVERY: u32 = 3; +const MIN_TEMPLATE_SIDE: usize = 8; +const COARSE_CANDIDATES: usize = 6; +const REFINE_RADIUS: isize = 2; +const LOCAL_RADIUS: f64 = 40.0; +const MIN_TEMPLATE_DEVIATION: f64 = 2.0; +const MIN_VISIBLE: f64 = 0.35; +const REACQUIRE_VISIBLE: f64 = 0.6; +const LOST_SCORE: f32 = 0.5; +const REACQUIRE_SCORE: f32 = 0.8; +const EXACT_SCORE: f32 = 0.93; +const EDGE_MARGIN: f64 = 0.25; +const REFRESH_SCORE: f32 = 0.85; +const SCALE_STEPS: [f64; 5] = [0.93, 0.965, 1.0, 1.035, 1.07]; +const REACQUIRE_SCALES: [f64; 7] = [0.5, 0.63, 0.8, 1.0, 1.25, 1.6, 2.0]; +const SCALE_GAIN: f32 = 0.004; +const MAX_BUFFERED_FRAMES: usize = 90; +pub(crate) const HOLD_LEAD: f64 = 0.01; +pub(crate) const BRIDGED_GAP: f64 = 0.4; + +#[derive(Clone)] +pub struct LumaFrame { + width: usize, + height: usize, + pixels: std::sync::Arc<[f32]>, +} + +impl LumaFrame { + pub fn from_rgba(data: &[u8], width: u32, height: u32, stride: usize) -> Self { + let (width, height) = (width as usize, height as usize); + let mut pixels = Vec::with_capacity(width * height); + for row in data.chunks(stride).take(height) { + pixels.extend(row[..width * 4].chunks_exact(4).map(|pixel| { + 0.299 * f32::from(pixel[0]) + + 0.587 * f32::from(pixel[1]) + + 0.114 * f32::from(pixel[2]) + })); + } + Self { + width, + height, + pixels: pixels.into(), + } + } + + pub fn width(&self) -> usize { + self.width + } + + pub fn height(&self) -> usize { + self.height + } + + fn crop(&self, x: usize, y: usize, width: usize, height: usize) -> Self { + let mut pixels = Vec::with_capacity(width * height); + for row in y..y + height { + let start = row * self.width + x; + pixels.extend_from_slice(&self.pixels[start..start + width]); + } + Self { + width, + height, + pixels: pixels.into(), + } + } + + fn half(&self) -> Self { + let (width, height) = (self.width / 2, self.height / 2); + let mut pixels = Vec::with_capacity(width * height); + for y in 0..height { + let top = &self.pixels[2 * y * self.width..]; + let bottom = &self.pixels[(2 * y + 1) * self.width..]; + pixels.extend( + (0..width).map(|x| { + (top[2 * x] + top[2 * x + 1] + bottom[2 * x] + bottom[2 * x + 1]) * 0.25 + }), + ); + } + Self { + width, + height, + pixels: pixels.into(), + } + } + + fn resized(&self, width: usize, height: usize) -> Self { + let mut source = std::borrow::Cow::Borrowed(self); + while source.width >= width * 2 && source.height >= height * 2 { + source = std::borrow::Cow::Owned(source.half()); + } + let scale_x = source.width as f32 / width as f32; + let scale_y = source.height as f32 / height as f32; + let mut pixels = Vec::with_capacity(width * height); + for y in 0..height { + let fy = ((y as f32 + 0.5) * scale_y - 0.5).clamp(0.0, (source.height - 1) as f32); + let (y0, ty) = (fy as usize, fy.fract()); + let y1 = (y0 + 1).min(source.height - 1); + for x in 0..width { + let fx = ((x as f32 + 0.5) * scale_x - 0.5).clamp(0.0, (source.width - 1) as f32); + let (x0, tx) = (fx as usize, fx.fract()); + let x1 = (x0 + 1).min(source.width - 1); + let at = |x: usize, y: usize| source.pixels[y * source.width + x]; + let top = at(x0, y0) + (at(x1, y0) - at(x0, y0)) * tx; + let bottom = at(x0, y1) + (at(x1, y1) - at(x0, y1)) * tx; + pixels.push(top + (bottom - top) * ty); + } + } + Self { + width, + height, + pixels: pixels.into(), + } + } +} + +fn taper(position: usize, length: usize) -> f32 { + let u = (position as f32 + 0.5) / length as f32; + let edge = u.min(1.0 - u) / 0.2; + if edge >= 1.0 { + 1.0 + } else { + 0.25 + 0.75 * (0.5 - 0.5 * (std::f32::consts::PI * edge).cos()) + } +} + +struct Template { + width: usize, + height: usize, + values: std::sync::Arc<[f32]>, + weights: Vec, + total_weight: f64, +} + +impl Template { + fn new(image: LumaFrame) -> Self { + let mut weights = Vec::with_capacity(image.pixels.len()); + for y in 0..image.height { + let wy = taper(y, image.height); + weights.extend((0..image.width).map(|x| wy * taper(x, image.width))); + } + let total_weight = weights.iter().map(|&w| f64::from(w)).sum(); + Self { + width: image.width, + height: image.height, + values: image.pixels, + weights, + total_weight, + } + } + + fn deviation(&self) -> f64 { + let (mut sw, mut st, mut stt) = (0.0f64, 0.0f64, 0.0f64); + for (&t, &w) in self.values.iter().zip(&self.weights) { + let (t, w) = (f64::from(t), f64::from(w)); + sw += w; + st += w * t; + stt += w * t * t; + } + ((stt - st * st / sw) / sw).max(0.0).sqrt() + } + + fn score(&self, frame: &LumaFrame, x: isize, y: isize, min_visible: f64) -> Option { + let x0 = x.max(0); + let y0 = y.max(0); + let x1 = (x + self.width as isize).min(frame.width as isize); + let y1 = (y + self.height as isize).min(frame.height as isize); + if x1 <= x0 || y1 <= y0 { + return None; + } + let (mut sw, mut st, mut si, mut stt, mut sii, mut sti) = (0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0); + let mut weight = 0.0f64; + for fy in y0..y1 { + let ty = (fy - y) as usize; + let row = &frame.pixels[fy as usize * frame.width..]; + let offset = ty * self.width + (x0 - x) as usize; + let count = (x1 - x0) as usize; + let image = &row[x0 as usize..x0 as usize + count]; + let values = &self.values[offset..offset + count]; + let weights = &self.weights[offset..offset + count]; + let (mut rw, mut rt, mut ri, mut rtt, mut rii, mut rti) = + (0.0f32, 0.0, 0.0, 0.0, 0.0, 0.0); + for ((&i, &t), &w) in image.iter().zip(values).zip(weights) { + let (wt, wi) = (w * t, w * i); + rw += w; + rt += wt; + ri += wi; + rtt += wt * t; + rii += wi * i; + rti += wt * i; + } + sw += rw; + st += rt; + si += ri; + stt += rtt; + sii += rii; + sti += rti; + weight += f64::from(rw); + } + if weight < min_visible * self.total_weight { + return None; + } + let (sw, st, si, stt, sii, sti) = ( + f64::from(sw), + f64::from(st), + f64::from(si), + f64::from(stt), + f64::from(sii), + f64::from(sti), + ); + let template_variance = stt - st * st / sw; + let image_variance = sii - si * si / sw; + if template_variance <= sw || image_variance <= sw { + return Some(0.0); + } + Some(((sti - st * si / sw) / (template_variance * image_variance).sqrt()) as f32) + } +} + +pub(crate) struct Pyramid(Vec); + +impl Pyramid { + pub(crate) fn new(frame: &LumaFrame) -> Self { + let mut levels = vec![frame.clone()]; + while levels.len() < MAX_LEVELS { + let next = levels[levels.len() - 1].half(); + levels.push(next); + } + Self(levels) + } +} + +/// A target's look at one capture, rescaled on demand to the box size the +/// tracker is searching for. +#[derive(Clone)] +struct Appearance { + reference: LumaFrame, +} + +impl Appearance { + fn templates(&self, width: usize, height: usize, min_side: usize) -> Vec