mirror of
https://github.com/huggingface/candle.git
synced 2025-06-15 10:26:33 +00:00
Update the image crate + use the re-exported version. (#1893)
* Update the image crate + use the re-exported version. * Update to using ab_glyph.
This commit is contained in:
@ -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 }
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user