feat(main): 优化图像处理和显示逻辑, 将部分功能移出线程, 提升性能

This commit is contained in:
conglinyizhi 2024-12-07 13:43:09 +08:00
parent a7e6a51914
commit 031c4bb7c8
1 changed files with 15 additions and 10 deletions

View File

@ -1,9 +1,9 @@
extern crate rscam;
use std::{env, time::Instant};
use std::{default, env, time::Instant};
use fltk::{
app::App,
enums::ColorDepth,
enums::{Align, ColorDepth},
frame::Frame,
image::RgbImage,
prelude::{GroupExt, WidgetBase, WidgetExt},
@ -23,10 +23,12 @@ fn main() {
let app = App::default();
let mut camera_window = Window::new(0, 0, 400, 400, "Camera Video Output Window");
let mut camera_frame = Frame::default_fill();
camera_frame.set_align(Align::LeftTop);
camera_window.end();
camera_window.show();
let mut color_window = Window::new(0, 400, 400, 400, "Video Output Window");
let mut color_window = Window::new(0, 450, 400, 400, "Video Output Window");
let mut color_frame = Frame::default_fill();
color_frame.set_align(Align::LeftTop);
color_window.end();
color_window.show();
// app.run().unwrap();
@ -77,13 +79,16 @@ fn main() {
println!("L8 Frame Draw use time: {:?}", duration);
})
.unwrap();
// 尝试将部分功能移出线程
crossbeam::scope(|_| {
let fltk_l_image =
RgbImage::new(l_data.as_raw(), w, h, ColorDepth::L8).unwrap();
camera_frame.set_image(Some(fltk_l_image));
camera_frame.set_size(w, h);
camera_frame.redraw();
let duration = start.elapsed();
println!("RGB8 Frame Draw use time: {:?}", duration);
})
.unwrap();
}
Err(e) => {
eprintln!("捕获错误: {}", e);