Browse Source

Adding 2d points

tags/v0.3.12-rc0
haixuantao 7 months ago
parent
commit
1f35724f15
3 changed files with 46 additions and 5 deletions
  1. +11
    -0
      examples/mediapipe/README.md
  2. +4
    -3
      examples/mediapipe/rgb-dev.yml
  3. +31
    -2
      node-hub/dora-rerun/src/lib.rs

+ 11
- 0
examples/mediapipe/README.md View File

@@ -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.
```

+ 4
- 3
examples/mediapipe/rgb-dev.yml View File

@@ -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

+ 31
- 2
node-hub/dora-rerun/src/lib.rs View File

@@ -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::<u8>(), 180, rand::random::<u8>());

color_cache.insert(id.clone(), color.clone());
color
};
let dataid = id;

// get a random color
if let Ok(buffer) = into_vec::<f32>(&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")?;
}


Loading…
Cancel
Save