Compare commits

..

No commits in common. "07c8591bfc13fb91662c36dad4a007e973fd2e82" and "478eaf29be7c1c7c89dad68cbe4ba43df9ed190f" have entirely different histories.

1 changed files with 16 additions and 49 deletions

View File

@ -1,5 +1,5 @@
extern crate rscam; extern crate rscam;
use std::{env, time::Instant}; use std::time::Instant;
use fltk::{ use fltk::{
app::App, app::App,
@ -9,36 +9,25 @@ use fltk::{
prelude::{GroupExt, WidgetBase, WidgetExt}, prelude::{GroupExt, WidgetBase, WidgetExt},
window::Window, window::Window,
}; };
use image::Rgb;
use rscam::{Camera, Config}; use rscam::{Camera, Config};
fn main() { fn main() {
let args: Vec<String> = env::args().collect();
println!("{:?}", args);
let camera_device = &args[1];
let w = args[2].clone();
let h = args[3].clone();
let fps = args[4].clone();
let mut camera_open = false; let mut camera_open = false;
let app = App::default(); let app = App::default();
let mut camera_window = Window::new(100, 100, 400, 300, "Camera Video Output Window"); let mut wind = Window::new(100, 100, 400, 300, "Hello from rust");
let mut camera_frame = Frame::default_fill(); let mut frame = Frame::default_fill();
camera_window.end(); wind.end();
camera_window.show(); wind.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(); // app.run().unwrap();
// 打开摄像头设备 // 打开摄像头设备
let mut camera = Camera::new(camera_device).unwrap(); let mut camera = Camera::new("/dev/video0").unwrap();
// 配置摄像头参数 // 配置摄像头参数
match camera.start(&Config { match camera.start(&Config {
// use command 'v4l2-ctl --list-formats-ext' see more... // use command 'v4l2-ctl --list-formats-ext' see more...
interval: (1, parse(fps)), // 设置帧率为 30fps interval: (1, 210), // 设置帧率为 30fps
resolution: (parse(w), parse(h)), // 设置分辨率为 640x480 resolution: (640, 400), // 设置分辨率为 640x480
format: b"MJPG", // 设置图像格式为 MJPG format: b"MJPG", // 设置图像格式为 MJPG
..Default::default() ..Default::default()
}) { }) {
Ok(_) => camera_open = true, Ok(_) => camera_open = true,
@ -55,25 +44,15 @@ fn main() {
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 rgb_data = img.to_luma8();
let mut rgb_data = img.to_rgb8();
if w == 0 { if w == 0 {
w = l_data.width() as i32; w = rgb_data.width() as i32;
h = l_data.height() as i32; h = rgb_data.height() as i32;
} }
for tmp_x in 0..30 { let fltk_image =
for tmp_y in 0..60 { RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::L8).unwrap();
rgb_data.put_pixel(tmp_x, tmp_y, Rgb([102, 204, 255])); 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(); let duration = start.elapsed();
println!("Time elapsed in DrawImage is: {:?}", duration); println!("Time elapsed in DrawImage is: {:?}", duration);
} }
@ -86,15 +65,3 @@ fn main() {
} }
} }
} }
/// 从 args 传入的数字转换为 u32
fn parse(str: String) -> u32 {
match str.parse::<u32>() {
Ok(data) => return data,
Err(e) => {
eprintln!("Error:${}", e);
println!("Note: rust-v4l2 <video_device> <width> <height> <interval>");
return 0;
}
}
}