Compare commits

...

3 Commits

Author SHA1 Message Date
conglinyizhi 33f0924adb feat(main): 添加时间测量功能 2024-12-07 10:01:17 +08:00
conglinyizhi 7bf1618646 feat(main): 优化图像处理逻辑 2024-12-07 09:55:09 +08:00
conglinyizhi 58792cdb39 🧹 chore(src): 删除 window.glade 文件,这原本是 GTK3 的配置文件,是遗留文件 2024-12-07 09:11:00 +08:00
2 changed files with 16 additions and 23 deletions

View File

@ -1,8 +1,11 @@
extern crate rscam;
use std::time::Instant;
use fltk::{
app::App,
enums::ColorDepth,
frame::Frame,
image::RgbImage,
prelude::{GroupExt, WidgetBase, WidgetExt},
window::Window,
};
@ -22,8 +25,8 @@ fn main() {
// 配置摄像头参数
match camera.start(&Config {
// use command 'v4l2-ctl --list-formats-ext' see more...
interval: (1, 30), // 设置帧率为 30fps
resolution: (640, 480), // 设置分辨率为 640x480
interval: (1, 210), // 设置帧率为 30fps
resolution: (640, 400), // 设置分辨率为 640x480
format: b"MJPG", // 设置图像格式为 MJPG
..Default::default()
}) {
@ -32,23 +35,26 @@ fn main() {
eprint!("Open Camera Error:{}", e)
}
}
let mut w = 0 as i32;
let mut h = 0 as i32;
if camera_open {
loop {
// 捕获一帧图像
match camera.capture() {
Ok(data) => {
let start = Instant::now();
let img = image::load_from_memory(&data).unwrap();
let rgb_data = img.to_rgb8();
let fltk_image = fltk::image::RgbImage::new(
&rgb_data.as_raw(),
rgb_data.width() as i32,
rgb_data.height() as i32,
ColorDepth::Rgb8,
)
.unwrap();
if w == 0 {
w = rgb_data.width() as i32;
h = rgb_data.height() as i32;
}
let fltk_image =
RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::Rgb8).unwrap();
frame.set_image(Some(fltk_image));
frame.redraw();
let duration = start.elapsed();
println!("Time elapsed in DrawImage is: {:?}", duration);
}
Err(e) => {
eprintln!("捕获错误: {}", e);

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window">
<property name="title">摄像头视频流</property>
<property name="default-width">640</property>
<property name="default-height">480</property>
<child>
<object class="GtkImage" id="image"/>
</child>
</object>
</interface>