diff --git a/Cargo.toml b/Cargo.toml index 776220d..780711c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,7 @@ thiserror = "1" flatbuffers = "^23" image = { version = "^0", default-features = false, optional = true } imageproc = { version = "^0", default-features = false, optional = true } -rusttype = { version = "^0", default-features = false, optional = true } -conv = { version = "^0", default-features = false, optional = true } +ab_glyph = { version = "^0", optional = true } regex = { version = "^1", optional = true } lazy_static = { version = "^1", optional = true } symphonia-core = { version = "^0", optional = true } @@ -50,7 +49,7 @@ branch = "wasm32-wasi" default = ["audio", "vision", "text"] audio = ["symphonia-core"] -vision = ["image", "imageproc", "rusttype", "lazy_static", "conv"] +vision = ["image", "imageproc", "lazy_static", "ab_glyph"] text = ["regex", "lazy_static"] ffmpeg = ["ffmpeg-next"] diff --git a/src/postprocess/containers/vision/detection_result.rs b/src/postprocess/containers/vision/detection_result.rs index 2ed8dea..b07d8a0 100644 --- a/src/postprocess/containers/vision/detection_result.rs +++ b/src/postprocess/containers/vision/detection_result.rs @@ -31,8 +31,7 @@ impl DetectionResult { where I: image::GenericImage, I::Pixel: 'static + DefaultPixel, - ::Subpixel: - conv::ValueInto + imageproc::definitions::Clamp, + ::Subpixel: Into + imageproc::definitions::Clamp, { draw_detection_with_options(img, self, &Default::default()); } @@ -43,8 +42,7 @@ impl DetectionResult { where I: image::GenericImage, I::Pixel: 'static, - ::Subpixel: - conv::ValueInto + imageproc::definitions::Clamp, + ::Subpixel: Into + imageproc::definitions::Clamp, { draw_detection_with_options(img, self, options); } diff --git a/src/postprocess/mod.rs b/src/postprocess/mod.rs index 012dade..f5d7cfd 100644 --- a/src/postprocess/mod.rs +++ b/src/postprocess/mod.rs @@ -10,5 +10,5 @@ pub(crate) use ops::{Activation, QuantizationParameters}; mod processing; pub(crate) use processing::*; -/// Utils to to make use of task results, such as drawing utils. +/// Utils to make use of task results, such as drawing utils. pub mod utils; diff --git a/src/postprocess/utils/vision/default_font/mod.rs b/src/postprocess/utils/vision/default_font/mod.rs index a1baabe..632631e 100644 --- a/src/postprocess/utils/vision/default_font/mod.rs +++ b/src/postprocess/utils/vision/default_font/mod.rs @@ -2,15 +2,15 @@ // The file `Roboto-Regulat.ttf` is downloaded from https://fonts.google.com/specimen/Roboto. // This font file is under Apache 2.0: https://github.com/googlefonts/roboto/blob/main/LICENSE -use rusttype::Font; +use ab_glyph::FontArc; const DEFAULT_FONT_BYTES: &[u8] = include_bytes!("./Roboto-Regular.ttf"); lazy_static::lazy_static! { - static ref DEFAULT_FONT: Font<'static> = Font::try_from_bytes(DEFAULT_FONT_BYTES).unwrap(); + static ref DEFAULT_FONT: FontArc = FontArc::try_from_slice(DEFAULT_FONT_BYTES).unwrap(); } /// Get default ascii font -pub fn default_font() -> &'static Font<'static> { +pub fn default_font() -> &'static FontArc { &DEFAULT_FONT } diff --git a/src/postprocess/utils/vision/draw_detections.rs b/src/postprocess/utils/vision/draw_detections.rs index 1717ec5..3e86cdf 100644 --- a/src/postprocess/utils/vision/draw_detections.rs +++ b/src/postprocess/utils/vision/draw_detections.rs @@ -1,8 +1,8 @@ use super::DefaultPixel; use crate::postprocess::DetectionResult; +use ab_glyph::{FontArc, PxScale}; use image::{GenericImage, Pixel}; use imageproc::{definitions::Clamp, drawing}; -use rusttype::{Font, Scale}; /// draw detection results options #[derive(Debug)] @@ -14,7 +14,7 @@ pub struct DrawDetectionsOptions<'font, P: Pixel> { pub keypoint_radius_percent: f32, pub draw_label: bool, - pub font: &'font Font<'font>, + pub font: &'font FontArc, pub font_color: P, pub font_scale: f32, } @@ -43,7 +43,7 @@ pub fn draw_detection(img: &mut I, detection_result: &DetectionResult) where I: GenericImage, I::Pixel: 'static + DefaultPixel, - ::Subpixel: conv::ValueInto + Clamp, + ::Subpixel: Into + Clamp, { draw_detection_with_options::(img, detection_result, &Default::default()) } @@ -55,7 +55,7 @@ pub fn draw_detection_with_options( options: &DrawDetectionsOptions, ) where I: GenericImage, - ::Subpixel: conv::ValueInto + Clamp, + ::Subpixel: Into + Clamp, I::Pixel: 'static, { let img_w = img.width() as f32; @@ -67,7 +67,7 @@ pub fn draw_detection_with_options( } else { options.keypoint_colors[0] }; - let font_scale = Scale { + let font_scale = PxScale { x: img_min * options.font_scale, y: img_min * options.font_scale, }; diff --git a/src/tasks/vision/hand_landmark/result.rs b/src/tasks/vision/hand_landmark/result.rs index ff449cb..54c637b 100644 --- a/src/tasks/vision/hand_landmark/result.rs +++ b/src/tasks/vision/hand_landmark/result.rs @@ -22,8 +22,7 @@ impl HandLandmarkResult { where I: image::GenericImage, I::Pixel: 'static + DefaultPixel, - ::Subpixel: - conv::ValueInto + imageproc::definitions::Clamp, + ::Subpixel: Into + imageproc::definitions::Clamp, { let mut options = DrawLandmarksOptions::default(); options.connections = HandLandmark::CONNECTIONS; @@ -36,8 +35,7 @@ impl HandLandmarkResult { where I: image::GenericImage, I::Pixel: 'static, - ::Subpixel: - conv::ValueInto + imageproc::definitions::Clamp, + ::Subpixel: Into + imageproc::definitions::Clamp, { draw_landmarks_with_options(img, &self.hand_landmarks, options); }