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 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:text_objects("54-0/ms-forms/paragraphs",paragraphs(ms_form))
|
||||
record:text_objects("54-0/ms-forms/lines",lines(ms_form))
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
image = { version = "0.24.7", features = ["png", "jpeg", "tiff"] }
|
||||
mlua = { workspace = true }
|
||||
rerun = "0.8.2"
|
||||
rerun = "0.9.0"
|
||||
serde_json = "1.0.107"
|
||||
serde = { version = "1.0.188", features = ["derive"] }
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::path::PathBuf;
|
||||
use mlua::{AnyUserData, Function, MetaMethod, Table, TableExt, UserData, UserDataRef};
|
||||
|
||||
use mlua::{AnyUserData, MetaMethod, UserData, UserDataRef};
|
||||
use mlua::prelude::*;
|
||||
use rerun::{MsgSender, RecordingStream, RecordingStreamBuilder};
|
||||
use rerun::components::{Rect2D, Tensor, Vec4D};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rerun::{Boxes2D, Image, MaybeOwnedComponentBatch, RecordingStream, RecordingStreamBuilder};
|
||||
use rerun::components::{Text};
|
||||
use rerun::datatypes::{TensorData, Vec4D};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TextObject {
|
||||
pub text: String,
|
||||
pub bbox: Rect2D,
|
||||
pub bbox: Boxes2D,
|
||||
}
|
||||
|
||||
impl UserData for TextObject {
|
||||
|
|
@ -24,7 +25,7 @@ impl UserData for TextObject {
|
|||
impl<'lua> FromLua<'lua> for TextObject {
|
||||
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 rect = table.get::<_, UserDataRef<Rect2D>>("bbox")?.clone();
|
||||
let rect = table.get::<_, UserDataRef<Boxes2D>>("bbox")?.clone();
|
||||
Ok(TextObject {
|
||||
text: table.get("text")?,
|
||||
bbox: rect
|
||||
|
|
@ -48,39 +49,42 @@ fn recording(lua: &Lua, name: String) -> LuaResult<AnyUserData> {
|
|||
}
|
||||
|
||||
fn rect_xyxy(lua: &Lua, points: [f32;4]) -> LuaResult<AnyUserData> {
|
||||
let rect = Rect2D::XYXY(Vec4D(points).into());
|
||||
lua.create_any_userdata(rect)
|
||||
let mut box2d = Boxes2D::from_mins_and_sizes(
|
||||
[(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<()> {
|
||||
|
||||
lua.register_userdata_type::<Rect2D>(|reg| {
|
||||
lua.register_userdata_type::<Boxes2D>(|reg| {
|
||||
reg.add_meta_method(MetaMethod::ToString, |lua, this, _:()| Ok(format!("{:?}", this)))
|
||||
})?;
|
||||
|
||||
lua.register_userdata_type::<RecordingStream>(|reg|{
|
||||
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}")))?;
|
||||
MsgSender::new(entity_path)
|
||||
.with_timeless(true)
|
||||
.with_component(&[image_tensor])
|
||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message: {}", error)))?
|
||||
.send(this)
|
||||
let image = Image::try_from(tensor).unwrap();
|
||||
this.log_timeless(entity_path, &image)
|
||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||
;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
reg.add_method("text_objects", |lua, this, (entity_path, objects): (String, Vec<TextObject>)| {
|
||||
let rects: Vec<Rect2D> = objects.into_iter()
|
||||
.map(|t| t.bbox)
|
||||
.collect();
|
||||
MsgSender::new(entity_path)
|
||||
.with_timeless(true)
|
||||
.with_component(rects.as_slice())
|
||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message: {}", error)))?
|
||||
.send(this)
|
||||
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||
// let rects: Vec<Boxes2D> = objects.into_iter()
|
||||
// .map(|t| t.bbox)
|
||||
// .collect();
|
||||
|
||||
for text_object in objects {
|
||||
this.log_timeless(
|
||||
entity_path.clone(),
|
||||
&text_object.bbox
|
||||
).map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue