From 3e12d0bd6de6313119c28163eec83b421c4f8c63 Mon Sep 17 00:00:00 2001 From: conglinyizhi Date: Sat, 7 Dec 2024 10:50:29 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(main):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=91=84=E5=83=8F=E5=A4=B4=E5=92=8C=E5=BD=A9=E8=89=B2=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=BE=93=E5=87=BA=E7=AA=97=E5=8F=A3,=20=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=94=AF=E6=8C=81=E7=81=B0=E5=BA=A6=E5=92=8CRGB?= =?UTF-8?q?=E5=9B=BE=E5=83=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index d389105..02d9ee0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,10 +14,14 @@ use rscam::{Camera, Config}; fn main() { let mut camera_open = false; let app = App::default(); - let mut wind = Window::new(100, 100, 400, 300, "Hello from rust"); - let mut frame = Frame::default_fill(); - wind.end(); - wind.show(); + let mut camera_window = Window::new(100, 100, 400, 300, "Camera Video Output Window"); + let mut camera_frame = Frame::default_fill(); + camera_window.end(); + camera_window.show(); + let mut color_window = Window::new(100, 600, 400, 300, "Video Output Window"); + let mut color_frame = Frame::default_fill(); + color_window.end(); + color_window.show(); // app.run().unwrap(); // 打开摄像头设备 let mut camera = Camera::new("/dev/video0").unwrap(); @@ -44,15 +48,20 @@ fn main() { Ok(data) => { let start = Instant::now(); let img = image::load_from_memory(&data).unwrap(); - let rgb_data = img.to_luma8(); + let l_data = img.to_luma8(); + let rgb_data = img.to_rgb8(); if w == 0 { - w = rgb_data.width() as i32; - h = rgb_data.height() as i32; + w = l_data.width() as i32; + h = l_data.height() as i32; } - let fltk_image = - RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::L8).unwrap(); - frame.set_image(Some(fltk_image)); - frame.redraw(); + let fltk_l_image = + RgbImage::new(&l_data.as_raw(), w, h, ColorDepth::L8).unwrap(); + let fltk_rgb_image = + RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::Rgb8).unwrap(); + camera_frame.set_image(Some(fltk_l_image)); + color_frame.set_image(Some(fltk_rgb_image)); + camera_frame.redraw(); + color_frame.redraw(); let duration = start.elapsed(); println!("Time elapsed in DrawImage is: {:?}", duration); }