Compare commits

..

No commits in common. "33f0924adb1628379ee78089d71762ee10bc558e" and "d8caf62e08c93a749e8ca899e93ae3b569a1c24b" have entirely different histories.

2 changed files with 23 additions and 16 deletions

View File

@ -1,11 +1,8 @@
extern crate rscam;
use std::time::Instant;
use fltk::{
app::App,
enums::ColorDepth,
frame::Frame,
image::RgbImage,
prelude::{GroupExt, WidgetBase, WidgetExt},
window::Window,
};
@ -25,8 +22,8 @@ fn main() {
// 配置摄像头参数
match camera.start(&Config {
// use command 'v4l2-ctl --list-formats-ext' see more...
interval: (1, 210), // 设置帧率为 30fps
resolution: (640, 400), // 设置分辨率为 640x480
interval: (1, 30), // 设置帧率为 30fps
resolution: (640, 480), // 设置分辨率为 640x480
format: b"MJPG", // 设置图像格式为 MJPG
..Default::default()
}) {
@ -35,26 +32,23 @@ 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();
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();
let fltk_image = fltk::image::RgbImage::new(
&rgb_data.as_raw(),
rgb_data.width() as i32,
rgb_data.height() as i32,
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);

13
src/window.glade Normal file
View File

@ -0,0 +1,13 @@
<?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>