rr: migrate to 0.9.0
parent
09990e545e
commit
e00703d24d
|
|
@ -2,12 +2,7 @@ local rr = require("rerun_lua")
|
||||||
|
|
||||||
|
|
||||||
function bbox(ms_ocr_bbox)
|
function bbox(ms_ocr_bbox)
|
||||||
return rr.rect_xyxy {
|
return rr.text_object(ms_ocr_bbox)
|
||||||
ms_ocr_bbox[1],
|
|
||||||
ms_ocr_bbox[2],
|
|
||||||
ms_ocr_bbox[5],
|
|
||||||
ms_ocr_bbox[6],
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function paragraphs(ms_form_result)
|
function paragraphs(ms_form_result)
|
||||||
|
|
@ -16,8 +11,7 @@ function paragraphs(ms_form_result)
|
||||||
for _, region in ipairs(paragraph.boundingRegions) do
|
for _, region in ipairs(paragraph.boundingRegions) do
|
||||||
table.insert(result, {
|
table.insert(result, {
|
||||||
text = paragraph.content,
|
text = paragraph.content,
|
||||||
page = region.pageNumber,
|
bbox = region.polygon
|
||||||
bbox = bbox(region.polygon)
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -30,8 +24,7 @@ function lines(ms_form_result)
|
||||||
for _, line in ipairs(page.lines) do
|
for _, line in ipairs(page.lines) do
|
||||||
table.insert(result, {
|
table.insert(result, {
|
||||||
text = line.content,
|
text = line.content,
|
||||||
page = page.pageNumber,
|
bbox = line.polygon
|
||||||
bbox = bbox(line.polygon)
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -46,8 +39,7 @@ function words(ms_form_result)
|
||||||
for _, word in ipairs(page.words) do
|
for _, word in ipairs(page.words) do
|
||||||
table.insert(result, {
|
table.insert(result, {
|
||||||
text = word.content,
|
text = word.content,
|
||||||
page = page.pageNumber,
|
bbox = word.polygon
|
||||||
bbox = bbox(word.polygon)
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -58,7 +50,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-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))
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,18 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use mlua::{AnyUserData, MetaMethod, UserData, UserDataRef};
|
use mlua::{AnyUserData, MetaMethod, UserData, UserDataRef};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use rerun::{Boxes2D, Image, MaybeOwnedComponentBatch, RecordingStream, RecordingStreamBuilder};
|
use rerun::{Boxes2D, Image, RecordingStream, RecordingStreamBuilder};
|
||||||
use rerun::components::{Text};
|
use rerun::datatypes::{TensorData, Vec2D, Vec4D};
|
||||||
use rerun::datatypes::{TensorData, Vec4D};
|
|
||||||
|
|
||||||
|
|
||||||
|
type TextBox = [f32;8];
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TextObject {
|
pub struct TextObject {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
pub bbox: Boxes2D,
|
pub bbox: TextBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl UserData for TextObject {
|
impl UserData for TextObject {
|
||||||
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
methods.add_meta_method(MetaMethod::ToString, |_lua, this, _:()| {
|
methods.add_meta_method(MetaMethod::ToString, |_lua, this, _:()| {
|
||||||
|
|
@ -25,10 +27,10 @@ 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<Boxes2D>>("bbox")?.clone();
|
let rect = table.get::<_, TextBox>("bbox")?;
|
||||||
Ok(TextObject {
|
Ok(TextObject {
|
||||||
text: table.get("text")?,
|
text: table.get("text")?,
|
||||||
bbox: rect
|
bbox: rect
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,13 +50,11 @@ fn recording(lua: &Lua, name: String) -> LuaResult<AnyUserData> {
|
||||||
lua.create_any_userdata(stream)
|
lua.create_any_userdata(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rect_xyxy(lua: &Lua, points: [f32;4]) -> LuaResult<AnyUserData> {
|
fn text_object(lua: &Lua, points: TextBox) -> LuaResult<TextObject> {
|
||||||
let mut box2d = Boxes2D::from_mins_and_sizes(
|
Ok(TextObject {
|
||||||
[(points[0], points[1])],
|
text: "".to_string(),
|
||||||
[(points[2] - points[0], points[3] - points[1])],
|
bbox: points,
|
||||||
);
|
})
|
||||||
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<()> {
|
||||||
|
|
@ -75,17 +75,25 @@ fn register_bindings(lua: &Lua) -> LuaResult<()> {
|
||||||
});
|
});
|
||||||
|
|
||||||
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<Boxes2D> = objects.into_iter()
|
let mins: Vec<Vec2D> = objects
|
||||||
// .map(|t| t.bbox)
|
.iter()
|
||||||
// .collect();
|
.map(|text_object| &text_object.bbox)
|
||||||
|
.map(|bbox| Vec2D([bbox[0], bbox[1]]) )
|
||||||
for text_object in objects {
|
.collect();
|
||||||
this.log_timeless(
|
let sizes: Vec<Vec2D> = objects
|
||||||
entity_path.clone(),
|
.iter()
|
||||||
&text_object.bbox
|
.map(|text_object| &text_object.bbox)
|
||||||
).map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
.map(|bbox| Vec2D([bbox[2] - bbox[0], bbox[7] - bbox[1]]) )
|
||||||
}
|
.collect();
|
||||||
|
let labels: Vec<String> = objects
|
||||||
|
.iter()
|
||||||
|
.map(|text_object| text_object.text.clone())
|
||||||
|
.collect();
|
||||||
|
let boxes2d = Boxes2D::from_mins_and_sizes(mins, sizes)
|
||||||
|
.with_labels(labels)
|
||||||
|
;
|
||||||
|
this.log_timeless(entity_path, &boxes2d)
|
||||||
|
.map_err(|error| LuaError::RuntimeError(format!("Could not send message {error}")))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -98,6 +106,6 @@ fn rerun_lua(lua: &Lua) -> LuaResult<LuaTable> {
|
||||||
let exports = lua.create_table()?;
|
let exports = lua.create_table()?;
|
||||||
exports.set("recording", lua.create_function(recording)?)?;
|
exports.set("recording", lua.create_function(recording)?)?;
|
||||||
exports.set("json", lua.create_function(json)?)?;
|
exports.set("json", lua.create_function(json)?)?;
|
||||||
exports.set("rect_xyxy", lua.create_function(rect_xyxy)?)?;
|
exports.set("text_object", lua.create_function(text_object)?)?;
|
||||||
Ok(exports)
|
Ok(exports)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue