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