rr: partially migrate to 0.9.0
parent
337b83450f
commit
09990e545e
File diff suppressed because it is too large
Load Diff
|
|
@ -58,6 +58,7 @@ end
|
||||||
local ms_form = rr.json("/Users/tbr/Desktop/ms_form.json")
|
local ms_form = rr.json("/Users/tbr/Desktop/ms_form.json")
|
||||||
|
|
||||||
local record = rr.recording("example-2")
|
local record = rr.recording("example-2")
|
||||||
|
record:image("54-1", "/Users/tbr/Desktop/00054-1.png")
|
||||||
record:image("54-0", "/Users/tbr/Desktop/00054-0.png")
|
record:image("54-0", "/Users/tbr/Desktop/00054-0.png")
|
||||||
record:text_objects("54-0/ms-forms/paragraphs",paragraphs(ms_form))
|
record:text_objects("54-0/ms-forms/paragraphs",paragraphs(ms_form))
|
||||||
record:text_objects("54-0/ms-forms/lines",lines(ms_form))
|
record:text_objects("54-0/ms-forms/lines",lines(ms_form))
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ crate-type = ["cdylib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
image = { version = "0.24.7", features = ["png", "jpeg", "tiff"] }
|
image = { version = "0.24.7", features = ["png", "jpeg", "tiff"] }
|
||||||
mlua = { workspace = true }
|
mlua = { workspace = true }
|
||||||
rerun = "0.8.2"
|
rerun = "0.9.0"
|
||||||
serde_json = "1.0.107"
|
serde_json = "1.0.107"
|
||||||
serde = { version = "1.0.188", features = ["derive"] }
|
serde = { version = "1.0.188", features = ["derive"] }
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use mlua::{AnyUserData, Function, MetaMethod, Table, TableExt, UserData, UserDataRef};
|
|
||||||
|
use mlua::{AnyUserData, MetaMethod, UserData, UserDataRef};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use rerun::{MsgSender, RecordingStream, RecordingStreamBuilder};
|
use rerun::{Boxes2D, Image, MaybeOwnedComponentBatch, RecordingStream, RecordingStreamBuilder};
|
||||||
use rerun::components::{Rect2D, Tensor, Vec4D};
|
use rerun::components::{Text};
|
||||||
use serde::{Deserialize, Serialize};
|
use rerun::datatypes::{TensorData, Vec4D};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TextObject {
|
pub struct TextObject {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub bbox: Rect2D,
|
pub bbox: Boxes2D,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserData for TextObject {
|
impl UserData for TextObject {
|
||||||
|
|
@ -24,7 +25,7 @@ impl UserData for TextObject {
|
||||||
impl<'lua> FromLua<'lua> for TextObject {
|
impl<'lua> FromLua<'lua> for TextObject {
|
||||||
fn from_lua(value: LuaValue<'lua>, lua: &'lua Lua) -> LuaResult<Self> {
|
fn from_lua(value: LuaValue<'lua>, lua: &'lua Lua) -> LuaResult<Self> {
|
||||||
let table = value.as_table().ok_or(LuaError::RuntimeError("invalid args for text_object".to_string()))?;
|
let table = value.as_table().ok_or(LuaError::RuntimeError("invalid args for text_object".to_string()))?;
|
||||||
let rect = table.get::<_, UserDataRef<Rect2D>>("bbox")?.clone();
|
let rect = table.get::<_, UserDataRef<Boxes2D>>("bbox")?.clone();
|
||||||
Ok(TextObject {
|
Ok(TextObject {
|
||||||
text: table.get("text")?,
|
text: table.get("text")?,
|
||||||
bbox: rect
|
bbox: rect
|
||||||
|
|
@ -48,39 +49,42 @@ fn recording(lua: &Lua, name: String) -> LuaResult<AnyUserData> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rect_xyxy(lua: &Lua, points: [f32;4]) -> LuaResult<AnyUserData> {
|
fn rect_xyxy(lua: &Lua, points: [f32;4]) -> LuaResult<AnyUserData> {
|
||||||
let rect = Rect2D::XYXY(Vec4D(points).into());
|
let mut box2d = Boxes2D::from_mins_and_sizes(
|
||||||
lua.create_any_userdata(rect)
|
[(points[0], points[1])],
|
||||||
|
[(points[2] - points[0], points[3] - points[1])],
|
||||||
|
);
|
||||||
|
box2d.labels = Some(vec![Text::from("A Label")]);
|
||||||
|
lua.create_any_userdata(box2d)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_bindings(lua: &Lua) -> LuaResult<()> {
|
fn register_bindings(lua: &Lua) -> LuaResult<()> {
|
||||||
|
|
||||||
lua.register_userdata_type::<Rect2D>(|reg| {
|
lua.register_userdata_type::<Boxes2D>(|reg| {
|
||||||
reg.add_meta_method(MetaMethod::ToString, |lua, this, _:()| Ok(format!("{:?}", this)))
|
reg.add_meta_method(MetaMethod::ToString, |lua, this, _:()| Ok(format!("{:?}", this)))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
lua.register_userdata_type::<RecordingStream>(|reg|{
|
lua.register_userdata_type::<RecordingStream>(|reg|{
|
||||||
reg.add_method("image", |lua, this, (entity_path, image_path): (String,String)| {
|
reg.add_method("image", |lua, this, (entity_path, image_path): (String,String)| {
|
||||||
let image_tensor = Tensor::from_image_file(PathBuf::from(image_path.as_str()).as_path())
|
let tensor = TensorData::from_image_file(PathBuf::from(image_path.as_str()).as_path())
|
||||||
.map_err(|error| LuaError::RuntimeError(format!("Could not read image file {image_path}. Error: {error}")))?;
|
.map_err(|error| LuaError::RuntimeError(format!("Could not read image file {image_path}. Error: {error}")))?;
|
||||||
MsgSender::new(entity_path)
|
let image = Image::try_from(tensor).unwrap();
|
||||||
.with_timeless(true)
|
this.log_timeless(entity_path, &image)
|
||||||
.with_component(&[image_tensor])
|
|
||||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message: {}", error)))?
|
|
||||||
.send(this)
|
|
||||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||||
|
;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
reg.add_method("text_objects", |lua, this, (entity_path, objects): (String, Vec<TextObject>)| {
|
reg.add_method("text_objects", |lua, this, (entity_path, objects): (String, Vec<TextObject>)| {
|
||||||
let rects: Vec<Rect2D> = objects.into_iter()
|
// let rects: Vec<Boxes2D> = objects.into_iter()
|
||||||
.map(|t| t.bbox)
|
// .map(|t| t.bbox)
|
||||||
.collect();
|
// .collect();
|
||||||
MsgSender::new(entity_path)
|
|
||||||
.with_timeless(true)
|
for text_object in objects {
|
||||||
.with_component(rects.as_slice())
|
this.log_timeless(
|
||||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message: {}", error)))?
|
entity_path.clone(),
|
||||||
.send(this)
|
&text_object.bbox
|
||||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
).map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue