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