Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
FP11a, FP11b: a note's marks teach. learn-notes makes a defect note's mark, box and lasso its row's region, grown and tracked over the label's span by EdgeTAM (raea-perceive track, from the note's frame forward and back; frames it loses dropped; grow.rs in raea-sys-fingerprint-use), and a span pin the row's time. The review player's marks and the agent's reading of arrows and strikes are in raea-feed
shinyobjectzc6acc166333d
diff --git a/apps/fingerprint/src/notes.rs b/apps/fingerprint/src/notes.rsindex 73a7cceb..a71627f7 100644--- a/apps/fingerprint/src/notes.rs+++ b/apps/fingerprint/src/notes.rs@@ -5,7 +5,8 @@//! --question`, answers to the "fingerprint" inbox), `readings --tally` counts how often the person agreed, and only//! once the kind is right 45 times in 50 and the axis 40 (FP5b) does `raea fingerprint learn-notes` make each defect//! or praise an evidence row over its span (1.5 s before the pin to 0.5 s after). A direction goes to the brief and the-//! agent, never into a head.+//! agent, never into a head. A note's marks (FP11b) make its row a region label: the box around its marks, boxes and+//! lassos; a span pin sets the row's time.use crate::{flag, has, words};use raea_sys_fingerprint::folder::Folder;@@ -37,6 +38,35 @@ pub struct Reading {pub kind_ok: Option<bool>,#[serde(default)]pub axis_ok: Option<bool>,+ /// a span pin's end: the label covers t..to (FP11b)+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub to: Option<f64>,+ /// where in the frame the note's marks say the thing is, x0,y0,x1,y1 in 0-1 (FP11b)+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub region: Option<[f32; 4]>,+}++/// How far a click reaches around its point, as a region, until a click is grown into its thing (FP11b, EdgeTAM)+const CLICK: f32 = 0.05;++/// The region a note's marks name: the box around its marks, boxes and lassos (a click as a small square around it).+/// Arrows and strikes are instructions for the agent, never a region+pub fn region(pin: &Value) -> Option<[f32; 4]> {+ let mut r: Option<[f32; 4]> = None;+ for m in pin["marks"].as_array().into_iter().flatten() {+ let reach = match m["kind"].as_str() {+ Some("mark") => CLICK,+ Some("box" | "lasso") => 0.0,+ _ => continue,+ };+ for p in m["points"].as_array().into_iter().flatten() {+ let (Some(x), Some(y)) = (p[0].as_f64(), p[1].as_f64()) else { continue };+ let (x, y) = (x as f32, y as f32);+ let b = [(x - reach).max(0.0), (y - reach).max(0.0), (x + reach).min(1.0), (y + reach).min(1.0)];+ r = Some(r.map_or(b, |a| [a[0].min(b[0]), a[1].min(b[1]), a[2].max(b[2]), a[3].max(b[3])]));+ }+ }+ r.filter(|a| a[2] > a[0] && a[3] > a[1])}/// A post's video on this machine: the renders library, else the project's own folder@@ -58,7 +88,8 @@ pub fn pinned(project: &Path) -> Vec<Reading> {if n["author"]["kind"] != "person" {continue;}- out.push(Reading { note: n["id"].as_str().unwrap_or("").into(), text: text.into(), who: n["author"]["name"].as_str().unwrap_or("me").into(), media: video.clone(), t, project: name.clone(), ..Default::default() });+ let to = n["pin"]["to"].as_f64().filter(|&to| to > t);+ out.push(Reading { note: n["id"].as_str().unwrap_or("").into(), text: text.into(), who: n["author"]["name"].as_str().unwrap_or("me").into(), media: video.clone(), t, project: name.clone(), to, region: region(&n["pin"]), ..Default::default() });}}out@@ -265,10 +296,13 @@ pub(crate) fn learn(enc: &mut raea_sys_columns::Encoders, dir: &Folder, l: &mut(None, true) => continue,};let c = enc.columns(&x.media)?;- let (a, b) = ((x.t - 1.5).max(0.0), (x.t + 0.5).min(c.dur));+ // a span is the label's time; a moment, 1.5 s before the pin to 0.5 s after (FP11b)+ let (a, b) = x.to.map_or(((x.t - 1.5).max(0.0), (x.t + 0.5).min(c.dur)), |to| (x.t.max(0.0), to.min(c.dur)));if b - a < 0.5 {continue;}+ // a defect's marks, grown into the thing and tracked over the label by EdgeTAM where raea-perceive is (grow.rs)+ let region = x.region.filter(|_| bad).map(|seed| raea_sys_fingerprint_use::grow::grow(&x.media, x.t, a, b, seed).ok().flatten().map_or(seed, |g| g.region));let row = raea_sys_fingerprint::evidence::Row {media: c.media.clone(),a,@@ -280,7 +314,7 @@ pub(crate) fn learn(enc: &mut raea_sys_columns::Encoders, dir: &Folder, l: &mutsource: "note".into(),project: x.project.clone(),kind: Some(x.note.clone()),- region: None,+ region,words: Some(x.text.clone()),at: 0,pin: None,@@ -295,6 +329,20 @@ pub(crate) fn learn(enc: &mut raea_sys_columns::Encoders, dir: &Folder, l: &mutmod tests {use super::*;+ #[test]+ fn marks_name_a_region_and_arrows_dont() {+ let pin = json!({"kind": "place", "x": 0.5, "y": 0.5, "marks": [+ {"kind": "box", "points": [[0.6, 0.7], [0.2, 0.3]]},+ {"kind": "mark", "points": [[0.9, 0.1]]},+ {"kind": "arrow", "points": [[0.0, 0.0], [1.0, 1.0]]}+ ]});+ let r = region(&pin).unwrap();+ let near = |a: f32, b: f32| (a - b).abs() < 1e-5;+ assert!(near(r[0], 0.2) && near(r[1], 0.05) && near(r[2], 0.95) && near(r[3], 0.7), "{r:?}");+ assert_eq!(region(&json!({"marks": [{"kind": "strike", "points": [[0.1, 0.1], [0.9, 0.9]]}]})), None, "a strike is for the agent");+ assert_eq!(region(&json!({"kind": "place", "x": 0.5, "y": 0.5})), None, "a pin is never a mark");+ }+#[test]fn a_reading_keeps_only_kinds_and_axes_it_knows() {let fp = raea_sys_fingerprint::taxonomy::base("me");diff --git a/docs/fingerprint.feature b/docs/fingerprint.featureindex fd19d3f5..53c852bf 100644--- a/docs/fingerprint.feature+++ b/docs/fingerprint.feature@@ -522,6 +522,10 @@ Feature: Fingerprint: a person's or a team's sense of good work, learned on theiAnd each mark is stored with the note, in the frame's 0-1 coordinates, with its frame or span and the layer keysunder it from the layer pass when the video has oneAnd a note without a mark keeps its pin, which is never read as a mark (FP0f)+ And so far (11-12, raea-feed fingerprint-page 2265d91): a pin dropped on the picture opens its composer with mark,+ box, lasso, arrow and strike tools; the next drag draws one, kept in pin.marks in 0-1 with its frame (`t`) and+ the layer keys under it on a render with a layer pass, and an opened note draws them again (e2e/marks.spec.ts).+ A span is the time pin's `to` (MomentComposer). Not yet: a box on a spectrogram, which the player doesn't show@needs:FP11aScenario: FP11b. What each mark teaches@@ -530,6 +534,11 @@ Feature: Fingerprint: a person's or a team's sense of good work, learned on theithe agent; a span sets the label's time; a spectrogram box is a time and frequency label on the soundAnd a click is grown into a region by EdgeTAM and tracked through its shot, so one mark labels every frame of it,with the frames EdgeTAM loses dropped+ And so far (11-12): the agent reads arrows, strikes and the marked thing as lines in the note's prompt and on a+ poster's line (raea-feed 02fc49a, model/pin.ts marksLines); `learn-notes` makes a defect note's mark, box and+ lasso its row's region, grown and tracked over the label's span by EdgeTAM (raea-perceive track, frames it+ loses dropped; on an app render a blind seed kept 3 frames of 10) and a span pin its time. Not yet: the spectrogram+ box, and tracking through the whole shot rather than the label's spanRule: FP12. Heatmaps: a picture axis says where, not only whether@needs:FP11b,FP2cdiff --git a/systems/columns/src/media.rs b/systems/columns/src/media.rsindex f39d07f8..5d53cbcc 100644--- a/systems/columns/src/media.rs+++ b/systems/columns/src/media.rs@@ -26,7 +26,8 @@ pub fn sha256(file: &Path) -> Result<String> {Ok(h.finalize().iter().map(|b| format!("{b:02x}")).collect())}-fn video(file: &Path) -> Result<Box<dyn raea_io_media::VideoDecoder>> {+/// The file's picture, opened by the first backend that can (also how a mark is grown into its thing, FP11b)+pub fn video(file: &Path) -> Result<Box<dyn raea_io_media::VideoDecoder>> {let mut why = Vec::new();for b in raea_io_media::preferred() {match b.open_video(file) {diff --git a/systems/fingerprint-use/Cargo.toml b/systems/fingerprint-use/Cargo.tomlindex ef374856..017e674b 100644--- a/systems/fingerprint-use/Cargo.toml+++ b/systems/fingerprint-use/Cargo.toml@@ -13,5 +13,5 @@ raea-sys-fingerprint = { path = "../fingerprint" }raea-sys-columns = { path = "../columns" }serde = { version = "1", features = ["derive"] }anyhow = "1"-# the sheet (sheet.rs) is a PNG+# the sheet (sheet.rs) is a PNG; a mark grown by EdgeTAM writes its frames and reads its mattes (grow.rs)image = { version = "0.25", default-features = false, features = ["png"] }diff --git a/systems/fingerprint-use/src/grow.rs b/systems/fingerprint-use/src/grow.rsnew file mode 100644index 00000000..7beafe05--- /dev/null+++ b/systems/fingerprint-use/src/grow.rs@@ -0,0 +1,144 @@+//! A mark grown into its thing (docs/fingerprint.feature FP11b): the region a note's click, box or lasso names is+//! tracked by EdgeTAM (raea-perceive track) forward from the note's frame to the end of its label and back to its+//! start, so one mark labels every frame of it. A frame where EdgeTAM loses the thing is dropped; the row's region is+//! the box around the frames it kept. Without raea-perceive the mark's own region stands.++use anyhow::{Result, anyhow};+use std::path::{Path, PathBuf};++/// Frames a second the thing is tracked at+const FPS: f64 = 4.0;+/// A tracked frame's longest side, pixels+const SIDE: u32 = 512;+/// Less of the frame than this, and EdgeTAM has lost the thing+const LOST: f64 = 0.0005;++#[derive(Clone, Debug, PartialEq)]+pub struct Grown {+ pub region: [f32; 4],+ pub kept: usize,+ pub lost: usize,+}++/// raea-perceive: $RAEA_PERCEIVE, else beside this raea, else on PATH+pub fn perceive() -> Option<PathBuf> {+ let name = if cfg!(windows) { "raea-perceive.exe" } else { "raea-perceive" };+ let beside = std::env::current_exe().ok().and_then(|e| e.canonicalize().ok()).and_then(|e| Some(e.parent()?.join(name)));+ let on_path = std::env::var_os("PATH").into_iter().flat_map(|p| std::env::split_paths(&p).collect::<Vec<_>>()).map(|d| d.join(name));+ std::env::var_os("RAEA_PERCEIVE").filter(|v| !v.is_empty()).map(PathBuf::from).into_iter().chain(beside).chain(on_path).find(|p| p.is_file())+}++/// The box around a matte's pixels at 128 or more, x0,y0,x1,y1 in 0-1; None when too little of it is on+pub fn bounds(matte: &[u8], w: usize, h: usize) -> Option<[f32; 4]> {+ let (mut x0, mut y0, mut x1, mut y1, mut n) = (w, h, 0, 0, 0usize);+ for y in 0..h {+ for x in 0..w {+ if matte[y * w + x] > 127 {+ (x0, y0, x1, y1, n) = (x0.min(x), y0.min(y), x1.max(x + 1), y1.max(y + 1), n + 1);+ }+ }+ }+ (n as f64 / (w * h).max(1) as f64 >= LOST).then(|| [x0 as f32 / w as f32, y0 as f32 / h as f32, x1 as f32 / w as f32, y1 as f32 / h as f32])+}++/// The box around boxes+pub fn union(a: Option<[f32; 4]>, b: [f32; 4]) -> [f32; 4] {+ a.map_or(b, |a| [a[0].min(b[0]), a[1].min(b[1]), a[2].max(b[2]), a[3].max(b[3])])+}++/// The note's frames from `from` toward `to` (either way), the first at `from`, as PNGs in `dir`+fn frames(media: &Path, from: f64, to: f64, dir: &Path) -> Result<Vec<PathBuf>> {+ let mut d = raea_sys_columns::media::video(media)?;+ let end = (d.info().duration - 1e-3).max(0.0);+ let n = ((to - from).abs() * FPS).floor() as usize + 1;+ let step = if to >= from { 1.0 / FPS } else { -1.0 / FPS };+ std::fs::create_dir_all(dir)?;+ let mut out = Vec::new();+ for i in 0..n {+ let t = (from + i as f64 * step).clamp(0.0, end);+ let f = d.frame_at(t).map_err(|e| anyhow!("{}: frame at {t:.2} s: {e}", media.display()))?;+ let img = image::RgbaImage::from_raw(f.width, f.height, f.rgba).ok_or_else(|| anyhow!("frame size"))?;+ let s = SIDE as f32 / f.width.max(f.height) as f32;+ let small = image::imageops::resize(&img, ((f.width as f32 * s) as u32).max(1), ((f.height as f32 * s) as u32).max(1), image::imageops::FilterType::Triangle);+ let p = dir.join(format!("f{i:03}.png"));+ small.save(&p)?;+ out.push(p);+ }+ Ok(out)+}++/// One run of EdgeTAM from `seed` on the first of `imgs`: each frame's box, None where it lost the thing+fn track(bin: &Path, seed: [f32; 4], imgs: &[PathBuf], out: &Path) -> Result<Vec<Option<[f32; 4]>>> {+ let b = format!("{},{},{},{}", seed[0], seed[1], (seed[2] - seed[0]).max(0.001), (seed[3] - seed[1]).max(0.001));+ let run = std::process::Command::new(bin).arg("track").arg(out).arg(&b).args(imgs).output()?;+ if !run.status.success() {+ return Err(anyhow!("raea-perceive track: {}", String::from_utf8_lossy(&run.stderr).trim()));+ }+ let mut boxes = Vec::new();+ for p in imgs {+ let m = image::open(out.join(p.file_name().unwrap_or_default()))?.to_luma8();+ boxes.push(bounds(m.as_raw(), m.width() as usize, m.height() as usize));+ }+ Ok(boxes)+}++/// The mark's region tracked over a..b from the note's moment `t`; Ok(None) without raea-perceive+pub fn grow(media: &Path, t: f64, a: f64, b: f64, seed: [f32; 4]) -> Result<Option<Grown>> {+ let Some(bin) = perceive() else { return Ok(None) };+ let tmp = std::env::temp_dir().join(format!("raea-fingerprint-grow-{}", std::process::id()));+ let ran = (|| -> Result<Grown> {+ let mut g = Grown { region: seed, kept: 0, lost: 0 };+ let mut region = None;+ for (i, end) in [b, a].into_iter().enumerate() {+ if (end - t).abs() * FPS < 1.0 && i == 1 {+ continue;+ }+ let dir = tmp.join(format!("{i}"));+ let imgs = frames(media, t, end, &dir.join("in"))?;+ for x in track(&bin, seed, &imgs, &dir.join("out"))? {+ match x {+ Some(r) => (region, g.kept) = (Some(union(region, r)), g.kept + 1),+ None => g.lost += 1,+ }+ }+ }+ g.region = region.unwrap_or(seed);+ Ok(g)+ })();+ let _ = std::fs::remove_dir_all(&tmp);+ ran.map(Some)+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn a_matte_s_box_and_a_lost_one() {+ let (w, h) = (10, 10);+ let mut m = vec![0u8; w * h];+ for y in 2..5 {+ for x in 6..9 {+ m[y * w + x] = 255;+ }+ }+ assert_eq!(bounds(&m, w, h), Some([0.6, 0.2, 0.9, 0.5]));+ assert_eq!(bounds(&vec![0u8; w * h], w, h), None, "nothing on is a lost frame");+ assert_eq!(union(Some([0.1, 0.5, 0.2, 0.6]), [0.6, 0.2, 0.9, 0.5]), [0.1, 0.2, 0.9, 0.6]);+ }+}++#[cfg(test)]+mod real {+ /// `RAEA_GROW_MEDIA=FILE cargo test -p raea-sys-fingerprint-use grows -- --ignored`: a box in the middle of FILE at 1 s,+ /// grown over 0..2 s by raea-perceive+ #[test]+ #[ignore]+ fn grows_on_a_real_render() {+ let f = std::path::PathBuf::from(std::env::var("RAEA_GROW_MEDIA").expect("RAEA_GROW_MEDIA"));+ let g = super::grow(&f, 1.0, 0.0, 2.0, [0.4, 0.4, 0.6, 0.6]).expect("grown").expect("raea-perceive");+ eprintln!("{g:?}");+ assert!(g.kept > 0, "EdgeTAM kept no frame");+ assert!(g.region[2] > g.region[0] && g.region[3] > g.region[1]);+ }+}diff --git a/systems/fingerprint-use/src/lib.rs b/systems/fingerprint-use/src/lib.rsindex cde4dd0b..6725b911 100644--- a/systems/fingerprint-use/src/lib.rs+++ b/systems/fingerprint-use/src/lib.rs@@ -5,8 +5,10 @@//! - which.rs: which fingerprint judges a piece: its project's, its workspace's, then the person's (FP14c)//! - diff.rs: where two fingerprints rank the same evidence differently (FP8b)//! - profile.rs: ranges from work the person admires, and a piece critiqued against them (FP6e)+//! - grow.rs: a note's mark grown into its thing and tracked over its label by EdgeTAM (FP11b)pub mod diff;+pub mod grow;pub mod profile;pub mod score;pub mod sheet;