From 18036c6ccbd216e0397fa6469bb50a8b8ea47892 Mon Sep 17 00:00:00 2001 From: Laurent Mazare Date: Thu, 21 Mar 2024 10:56:41 +0100 Subject: [PATCH] Update the image crate + use the re-exported version. (#1893) * Update the image crate + use the re-exported version. * Update to using ab_glyph. --- Cargo.toml | 6 +-- candle-examples/Cargo.toml | 2 +- candle-examples/examples/segformer/main.rs | 2 +- candle-examples/examples/yolo-v8/main.rs | 45 +++++++++++----------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a3e1983..1f0067b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ categories = ["science"] license = "MIT OR Apache-2.0" [workspace.dependencies] +ab_glyph = "0.2.23" accelerate-src = { version = "0.3.2" } anyhow = { version = "1", features = ["backtrace"] } byteorder = "1.4.3" @@ -46,8 +47,8 @@ fancy-regex = "0.13.0" gemm = { version = "0.17.0", features = ["wasm-simd128-enable"] } hf-hub = "0.3.0" half = { version = "2.3.1", features = ["num-traits", "use-intrinsics", "rand_distr"] } -image = { version = "0.24.7", default-features = false, features = ["jpeg", "png"] } -imageproc = { version = "0.23.0", default-features = false } +image = { version = "0.25.0", default-features = false, features = ["jpeg", "png"] } +imageproc = { version = "0.24.0", default-features = false } intel-mkl-src = { version = "0.8.1", features = ["mkl-static-lp64-iomp"] } libc = { version = "0.2.147" } log = "0.4" @@ -58,7 +59,6 @@ parquet = { version = "50.0.0" } rand = "0.8.5" rand_distr = "0.4.3" rayon = "1.7.0" -rusttype = { version = "0.9", default-features = false } safetensors = "0.4.1" serde = { version = "1.0.171", features = ["derive"] } serde_plain = "1.0.2" diff --git a/candle-examples/Cargo.toml b/candle-examples/Cargo.toml index 108ca32a..864d2f6a 100644 --- a/candle-examples/Cargo.toml +++ b/candle-examples/Cargo.toml @@ -42,7 +42,7 @@ clap = { workspace = true } imageproc = { workspace = true } memmap2 = { workspace = true } rand = { workspace = true } -rusttype = { workspace = true } +ab_glyph = { workspace = true } tracing = { workspace = true } tracing-chrome = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/candle-examples/examples/segformer/main.rs b/candle-examples/examples/segformer/main.rs index 76c9f30e..16db62fc 100644 --- a/candle-examples/examples/segformer/main.rs +++ b/candle-examples/examples/segformer/main.rs @@ -5,7 +5,7 @@ use candle_transformers::models::segformer::{ Config, ImageClassificationModel, SemanticSegmentationModel, }; use clap::{Args, Parser, Subcommand}; -use image::Rgb; +use imageproc::image::Rgb; use imageproc::integral_image::ArrayData; use std::collections::HashMap; use std::path::PathBuf; diff --git a/candle-examples/examples/yolo-v8/main.rs b/candle-examples/examples/yolo-v8/main.rs index c65a5ca1..eb338647 100644 --- a/candle-examples/examples/yolo-v8/main.rs +++ b/candle-examples/examples/yolo-v8/main.rs @@ -99,7 +99,7 @@ pub fn report_detect( let h_ratio = initial_h as f32 / h as f32; let mut img = img.to_rgb8(); let font = Vec::from(include_bytes!("roboto-mono-stripped.ttf") as &[u8]); - let font = rusttype::Font::try_from_vec(font); + let font = ab_glyph::FontRef::try_from_slice(&font).map_err(candle::Error::wrap)?; for (class_index, bboxes_for_class) in bboxes.iter().enumerate() { for b in bboxes_for_class.iter() { println!( @@ -119,27 +119,28 @@ pub fn report_detect( ); } if legend_size > 0 { - if let Some(font) = font.as_ref() { - imageproc::drawing::draw_filled_rect_mut( - &mut img, - imageproc::rect::Rect::at(xmin, ymin).of_size(dx as u32, legend_size), - image::Rgb([170, 0, 0]), - ); - let legend = format!( - "{} {:.0}%", - candle_examples::coco_classes::NAMES[class_index], - 100. * b.confidence - ); - imageproc::drawing::draw_text_mut( - &mut img, - image::Rgb([255, 255, 255]), - xmin, - ymin, - rusttype::Scale::uniform(legend_size as f32 - 1.), - font, - &legend, - ) - } + imageproc::drawing::draw_filled_rect_mut( + &mut img, + imageproc::rect::Rect::at(xmin, ymin).of_size(dx as u32, legend_size), + image::Rgb([170, 0, 0]), + ); + let legend = format!( + "{} {:.0}%", + candle_examples::coco_classes::NAMES[class_index], + 100. * b.confidence + ); + imageproc::drawing::draw_text_mut( + &mut img, + image::Rgb([255, 255, 255]), + xmin, + ymin, + ab_glyph::PxScale { + x: legend_size as f32 - 1., + y: legend_size as f32 - 1., + }, + &font, + &legend, + ) } } }