Compare commits

..

No commits in common. "a23b117752f71e38170db931c792770071a180bf" and "031c4bb7c899b537b45614f53fad254d1d72ac45" have entirely different histories.

1 changed files with 26 additions and 25 deletions

View File

@ -23,12 +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::Center); 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, 450, 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::Center); color_frame.set_align(Align::LeftTop);
color_window.end(); color_window.end();
color_window.show(); color_window.show();
// app.run().unwrap(); // app.run().unwrap();
@ -51,20 +51,19 @@ 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() { Ok(data) => {
Ok(data) => { let start = Instant::now();
let start = Instant::now(); let img = image::load_from_memory(&data).unwrap();
let img = image::load_from_memory(&data).unwrap(); let l_data = img.to_luma8();
let l_data = img.to_luma8(); let mut rgb_data = img.to_rgb8();
let mut rgb_data = img.to_rgb8(); if w == 0 {
if w == 0 { 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]));
@ -78,7 +77,9 @@ 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));
@ -86,16 +87,16 @@ 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);
} })
Err(e) => { .unwrap();
eprintln!("捕获错误: {}", e); }
continue; Err(e) => {
} eprintln!("捕获错误: {}", e);
continue;
} }
app.wait();
} }
}) app.wait();
.unwrap(); }
} }
} }