Skip to content

Commit 1f35724

Browse files
committed
Adding 2d points
1 parent ca031e1 commit 1f35724

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

examples/mediapipe/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Mediapipe example
2+
3+
## Make sure to have a webcam connected
4+
5+
```bash
6+
uv venv --seed
7+
dora build rgb-dev.yml --uv
8+
dora run rgb-dev.yml --uv
9+
10+
## If the points are not plotted by default, you should try to add a 2d viewer within rerun.
11+
```

examples/mediapipe/rgb-dev.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
nodes:
22
- id: camera
3-
build: pip install opencv-video-capture
3+
build: pip install -e ../../node-hub/opencv-video-capture
44
path: opencv-video-capture
55
inputs:
66
tick: dora/timer/millis/100
@@ -18,8 +18,9 @@ nodes:
1818
- points2d
1919

2020
- id: plot
21-
build: pip install dora-rerun
21+
build: pip install -e ../../node-hub/dora-rerun
2222
path: dora-rerun
2323
inputs:
2424
image: camera/image
25-
series_mediapipe: dora-mediapipe/points2d
25+
# Make sure to add a 2d viewer to see the points
26+
points2d: dora-mediapipe/points2d

node-hub/dora-rerun/src/lib.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ use std::{collections::HashMap, env::VarError, path::Path};
44

55
use dora_node_api::{
66
arrow::{
7-
array::{Array, AsArray, Float32Array, Float64Array, StringArray, UInt16Array, UInt8Array},
7+
array::{Array, AsArray, Float64Array, StringArray, UInt16Array, UInt8Array},
88
datatypes::Float32Type,
99
},
1010
dora_core::config::DataId,
1111
into_vec, DoraNode, Event, Parameter,
1212
};
1313
use eyre::{eyre, Context, Result};
1414

15-
use rerun::{components::ImageBuffer, external::log::warn, ImageFormat, Points3D, SpawnOptions};
15+
use rerun::{
16+
components::ImageBuffer, external::log::warn, ImageFormat, Points2D, Points3D, SpawnOptions,
17+
};
1618
pub mod boxes2d;
1719
pub mod series;
1820
pub mod urdf;
@@ -374,6 +376,33 @@ pub fn lib_main() -> Result<()> {
374376
});
375377
let points = Points3D::new(points).with_radii(vec![0.013; colors.len()]);
376378

379+
rec.log(dataid.as_str(), &points.with_colors(colors))
380+
.context("could not log points")?;
381+
}
382+
} else if id.as_str().contains("points2d") {
383+
// Get color or assign random color in cache
384+
let color = color_cache.get(&id);
385+
let color = if let Some(color) = color {
386+
color.clone()
387+
} else {
388+
let color =
389+
rerun::Color::from_rgb(rand::random::<u8>(), 180, rand::random::<u8>());
390+
391+
color_cache.insert(id.clone(), color.clone());
392+
color
393+
};
394+
let dataid = id;
395+
396+
// get a random color
397+
if let Ok(buffer) = into_vec::<f32>(&data) {
398+
let mut points = vec![];
399+
let mut colors = vec![];
400+
buffer.chunks(2).for_each(|chunk| {
401+
points.push((chunk[0], chunk[1]));
402+
colors.push(color);
403+
});
404+
let points = Points2D::new(points);
405+
377406
rec.log(dataid.as_str(), &points.with_colors(colors))
378407
.context("could not log points")?;
379408
}

0 commit comments

Comments
 (0)