Change errors to anyhow, fix improperly oriented tensor
This commit is contained in:
@@ -1,24 +1,22 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::error::Error;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use rten_tensor::{NdTensor, AsView};
|
use rten_tensor::{NdTensor, AsView};
|
||||||
use rten::Model;
|
use rten::Model;
|
||||||
use ocrs::{OcrEngine, OcrEngineParams};
|
use ocrs::{OcrEngine, OcrEngineParams};
|
||||||
|
|
||||||
pub fn print_words(image: NdTensor<f32, 3>) -> Result<(), Box<dyn Error>> {
|
pub fn print_words(image: NdTensor<f32, 3>) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let begin = Instant::now();
|
let begin = Instant::now();
|
||||||
|
|
||||||
println!("{:#?}", begin.elapsed());
|
|
||||||
let begin = Instant::now();
|
|
||||||
ocr(image).unwrap();
|
ocr(image).unwrap();
|
||||||
|
|
||||||
println!("{:#?}", begin.elapsed());
|
println!("{:#?}", begin.elapsed());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ocr(data: NdTensor<f32, 3>) -> Result<(), Box<dyn Error>> {
|
fn ocr(data: NdTensor<f32, 3>) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let detection_model_data = fs::read("text-detection.rten")?;
|
let detection_model_data = fs::read("text-detection.rten")?;
|
||||||
let rec_model_data = fs::read("text-recognition.rten")?;
|
let rec_model_data = fs::read("text-recognition.rten")?;
|
||||||
|
|||||||
@@ -31,13 +31,10 @@ use wayland_client::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use anyhow;
|
||||||
use rten_tensor::NdTensor;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
use crate::wayland::{
|
use crate::wayland::{
|
||||||
draw::{DrawPath, Draw},
|
draw::DrawPath,
|
||||||
builder::{TextAreaBuilder, DrawAreaBuilder, ButtonBuilder},
|
builder::{TextAreaBuilder, DrawAreaBuilder, ButtonBuilder},
|
||||||
ui::{self, Widget, ButtonType},
|
ui::{self, Widget, ButtonType},
|
||||||
Position,
|
Position,
|
||||||
@@ -71,7 +68,7 @@ pub(crate) struct SimpleWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SimpleWindow {
|
impl SimpleWindow {
|
||||||
pub(crate) fn run() -> Result<()> {
|
pub(crate) fn run() -> anyhow::Result<()> {
|
||||||
let conn = Connection::connect_to_env()?;
|
let conn = Connection::connect_to_env()?;
|
||||||
|
|
||||||
let (globals, event_queue) = registry_queue_init(&conn)?;
|
let (globals, event_queue) = registry_queue_init(&conn)?;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl<'a> TextAreaBuilder {
|
|||||||
self.position = Some(Position::new(x, y))
|
self.position = Some(Position::new(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) fn colors(&mut self, colors: TextAreaColors) {
|
pub(super) fn colors(&mut self, colors: TextAreaColors) {
|
||||||
self.colors = Some(colors);
|
self.colors = Some(colors);
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,7 @@ impl ButtonBuilder {
|
|||||||
self.position = Some(Position::new(x as f32, y as f32))
|
self.position = Some(Position::new(x as f32, y as f32))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) fn colors(&mut self, colors: ButtonColors) {
|
pub(super) fn colors(&mut self, colors: ButtonColors) {
|
||||||
self.colors = Some(colors)
|
self.colors = Some(colors)
|
||||||
}
|
}
|
||||||
@@ -156,6 +157,7 @@ impl DrawAreaBuilder {
|
|||||||
self.position = Some(Position::new(x, y))
|
self.position = Some(Position::new(x, y))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) fn colors(&mut self, colors: DrawAreaColors) {
|
pub(super) fn colors(&mut self, colors: DrawAreaColors) {
|
||||||
self.colors = Some(colors)
|
self.colors = Some(colors)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use raqote::{DrawTarget, Color, StrokeStyle, PathBuilder, Source, DrawOptions, S
|
|||||||
use rten_tensor::NdTensor;
|
use rten_tensor::NdTensor;
|
||||||
|
|
||||||
use crate::wayland::Position;
|
use crate::wayland::Position;
|
||||||
use crate::process_point::print_words;
|
|
||||||
|
|
||||||
pub(super) trait Draw {
|
pub(super) trait Draw {
|
||||||
fn render(&self, area: &mut DrawTarget<&mut [u32]>);
|
fn render(&self, area: &mut DrawTarget<&mut [u32]>);
|
||||||
@@ -35,6 +34,7 @@ impl DrawPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) fn into_iter(self) -> std::vec::IntoIter<Path> {
|
pub(crate) fn into_iter(self) -> std::vec::IntoIter<Path> {
|
||||||
self.paths.into_iter()
|
self.paths.into_iter()
|
||||||
}
|
}
|
||||||
@@ -43,11 +43,13 @@ impl DrawPath {
|
|||||||
self.paths.iter()
|
self.paths.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(crate) fn iter_mut(&mut self) -> std::slice::IterMut<Path> {
|
pub(crate) fn iter_mut(&mut self) -> std::slice::IterMut<Path> {
|
||||||
self.paths.iter_mut()
|
self.paths.iter_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) struct DrawAreaColors {
|
pub(super) struct DrawAreaColors {
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
drawing_color: Color,
|
drawing_color: Color,
|
||||||
@@ -83,6 +85,7 @@ impl DrawArea {
|
|||||||
Source::Solid(self.colors.drawing_color.into())
|
Source::Solid(self.colors.drawing_color.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
fn border_source(&self) -> Source {
|
fn border_source(&self) -> Source {
|
||||||
Source::Solid(self.colors.border_color.into())
|
Source::Solid(self.colors.border_color.into())
|
||||||
}
|
}
|
||||||
@@ -161,7 +164,7 @@ impl From<&DrawArea> for NdTensor<f32, 3> {
|
|||||||
image::ImageFormat::Png
|
image::ImageFormat::Png
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
NdTensor::from_data([1, draw_area.width as usize, draw_area.height as usize], data)
|
NdTensor::from_data([1, draw_area.height, draw_area.width], data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::wayland::{
|
|||||||
Position,
|
Position,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) struct UIColors {
|
pub(super) struct UIColors {
|
||||||
draw_area: Color,
|
draw_area: Color,
|
||||||
button: Color,
|
button: Color,
|
||||||
@@ -87,6 +88,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) struct ButtonColors {
|
pub(super) struct ButtonColors {
|
||||||
background: Color,
|
background: Color,
|
||||||
border: Color,
|
border: Color,
|
||||||
@@ -109,6 +111,7 @@ pub(super) enum ButtonType {
|
|||||||
Enter,
|
Enter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) struct Button {
|
pub(super) struct Button {
|
||||||
pub(super) button_type: ButtonType,
|
pub(super) button_type: ButtonType,
|
||||||
pub(super) width: usize,
|
pub(super) width: usize,
|
||||||
@@ -141,6 +144,7 @@ impl Draw for Button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) struct TextAreaColors {
|
pub(super) struct TextAreaColors {
|
||||||
pub(super) background: Color,
|
pub(super) background: Color,
|
||||||
pub(super) text: Color,
|
pub(super) text: Color,
|
||||||
@@ -164,6 +168,7 @@ pub(super) struct TextArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TextArea {
|
impl TextArea {
|
||||||
|
#[allow(unused)]
|
||||||
pub(super) fn text_source(&self) -> Source {
|
pub(super) fn text_source(&self) -> Source {
|
||||||
Source::Solid(self.colors.text.into())
|
Source::Solid(self.colors.text.into())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user