From 1f35724f1541b13a4eba8be6cb78d09a2b73eb4d Mon Sep 17 00:00:00 2001 From: haixuantao Date: Fri, 30 May 2025 17:09:06 +0200 Subject: [PATCH] Adding 2d points --- examples/mediapipe/README.md | 11 +++++++++++ examples/mediapipe/rgb-dev.yml | 7 ++++--- node-hub/dora-rerun/src/lib.rs | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 examples/mediapipe/README.md diff --git a/examples/mediapipe/README.md b/examples/mediapipe/README.md new file mode 100644 index 00000000..e11257ad --- /dev/null +++ b/examples/mediapipe/README.md @@ -0,0 +1,11 @@ +# Mediapipe example + +## Make sure to have a webcam connected + +```bash +uv venv --seed +dora build rgb-dev.yml --uv +dora run rgb-dev.yml --uv + +## If the points are not plotted by default, you should try to add a 2d viewer within rerun. +``` diff --git a/examples/mediapipe/rgb-dev.yml b/examples/mediapipe/rgb-dev.yml index 1517f8f1..acfe193b 100755 --- a/examples/mediapipe/rgb-dev.yml +++ b/examples/mediapipe/rgb-dev.yml @@ -1,6 +1,6 @@ nodes: - id: camera - build: pip install opencv-video-capture + build: pip install -e ../../node-hub/opencv-video-capture path: opencv-video-capture inputs: tick: dora/timer/millis/100 @@ -18,8 +18,9 @@ nodes: - points2d - id: plot - build: pip install dora-rerun + build: pip install -e ../../node-hub/dora-rerun path: dora-rerun inputs: image: camera/image - series_mediapipe: dora-mediapipe/points2d + # Make sure to add a 2d viewer to see the points + points2d: dora-mediapipe/points2d diff --git a/node-hub/dora-rerun/src/lib.rs b/node-hub/dora-rerun/src/lib.rs index 726806b6..a0539280 100644 --- a/node-hub/dora-rerun/src/lib.rs +++ b/node-hub/dora-rerun/src/lib.rs @@ -4,7 +4,7 @@ use std::{collections::HashMap, env::VarError, path::Path}; use dora_node_api::{ arrow::{ - array::{Array, AsArray, Float32Array, Float64Array, StringArray, UInt16Array, UInt8Array}, + array::{Array, AsArray, Float64Array, StringArray, UInt16Array, UInt8Array}, datatypes::Float32Type, }, dora_core::config::DataId, @@ -12,7 +12,9 @@ use dora_node_api::{ }; use eyre::{eyre, Context, Result}; -use rerun::{components::ImageBuffer, external::log::warn, ImageFormat, Points3D, SpawnOptions}; +use rerun::{ + components::ImageBuffer, external::log::warn, ImageFormat, Points2D, Points3D, SpawnOptions, +}; pub mod boxes2d; pub mod series; pub mod urdf; @@ -374,6 +376,33 @@ pub fn lib_main() -> Result<()> { }); let points = Points3D::new(points).with_radii(vec![0.013; colors.len()]); + rec.log(dataid.as_str(), &points.with_colors(colors)) + .context("could not log points")?; + } + } else if id.as_str().contains("points2d") { + // Get color or assign random color in cache + let color = color_cache.get(&id); + let color = if let Some(color) = color { + color.clone() + } else { + let color = + rerun::Color::from_rgb(rand::random::(), 180, rand::random::()); + + color_cache.insert(id.clone(), color.clone()); + color + }; + let dataid = id; + + // get a random color + if let Ok(buffer) = into_vec::(&data) { + let mut points = vec![]; + let mut colors = vec![]; + buffer.chunks(2).for_each(|chunk| { + points.push((chunk[0], chunk[1])); + colors.push(color); + }); + let points = Points2D::new(points); + rec.log(dataid.as_str(), &points.with_colors(colors)) .context("could not log points")?; }