✨ feat(main): 重构图像捕获和处理逻辑,提升代码可读性和维护性
This commit is contained in:
parent
8a15ee2c7c
commit
a23b117752
11
src/main.rs
11
src/main.rs
|
@ -51,6 +51,7 @@ fn main() {
|
||||||
let mut w = 0;
|
let mut w = 0;
|
||||||
let mut h = 0;
|
let mut h = 0;
|
||||||
if camera_open {
|
if camera_open {
|
||||||
|
crossbeam::scope(|_| {
|
||||||
loop {
|
loop {
|
||||||
// 捕获一帧图像
|
// 捕获一帧图像
|
||||||
match camera.capture() {
|
match camera.capture() {
|
||||||
|
@ -63,7 +64,7 @@ fn main() {
|
||||||
w = l_data.width() as i32;
|
w = l_data.width() as i32;
|
||||||
h = l_data.height() as i32;
|
h = l_data.height() as i32;
|
||||||
}
|
}
|
||||||
crossbeam::scope(|_| {
|
|
||||||
for tmp_x in 0..30 {
|
for tmp_x in 0..30 {
|
||||||
for tmp_y in 0..60 {
|
for tmp_y in 0..60 {
|
||||||
rgb_data.put_pixel(tmp_x, tmp_y, Rgb([102, 204, 255]));
|
rgb_data.put_pixel(tmp_x, tmp_y, Rgb([102, 204, 255]));
|
||||||
|
@ -77,9 +78,7 @@ fn main() {
|
||||||
color_frame.redraw();
|
color_frame.redraw();
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
println!("L8 Frame Draw use time: {:?}", duration);
|
println!("L8 Frame Draw use time: {:?}", duration);
|
||||||
})
|
|
||||||
.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));
|
||||||
|
@ -87,8 +86,6 @@ fn main() {
|
||||||
camera_frame.redraw();
|
camera_frame.redraw();
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
println!("RGB8 Frame Draw use time: {:?}", duration);
|
println!("RGB8 Frame Draw use time: {:?}", duration);
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("捕获错误: {}", e);
|
eprintln!("捕获错误: {}", e);
|
||||||
|
@ -97,6 +94,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
app.wait();
|
app.wait();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue