feat(main): 优化图像处理逻辑

This commit is contained in:
conglinyizhi 2024-12-07 09:55:09 +08:00
parent 58792cdb39
commit 7bf1618646
1 changed files with 9 additions and 8 deletions

View File

@ -3,6 +3,7 @@ use fltk::{
app::App,
enums::ColorDepth,
frame::Frame,
image::RgbImage,
prelude::{GroupExt, WidgetBase, WidgetExt},
window::Window,
};
@ -32,6 +33,8 @@ fn main() {
eprint!("Open Camera Error:{}", e)
}
}
let mut w = 0 as i32;
let mut h = 0 as i32;
if camera_open {
loop {
// 捕获一帧图像
@ -39,14 +42,12 @@ fn main() {
Ok(data) => {
let img = image::load_from_memory(&data).unwrap();
let rgb_data = img.to_rgb8();
let fltk_image = fltk::image::RgbImage::new(
&rgb_data.as_raw(),
rgb_data.width() as i32,
rgb_data.height() as i32,
ColorDepth::Rgb8,
)
.unwrap();
if w == 0 {
w = rgb_data.width() as i32;
h = rgb_data.height() as i32;
}
let fltk_image =
RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::Rgb8).unwrap();
frame.set_image(Some(fltk_image));
frame.redraw();
}