Compare commits
No commits in common. "33f0924adb1628379ee78089d71762ee10bc558e" and "d8caf62e08c93a749e8ca899e93ae3b569a1c24b" have entirely different histories.
33f0924adb
...
d8caf62e08
26
src/main.rs
26
src/main.rs
|
@ -1,11 +1,8 @@
|
||||||
extern crate rscam;
|
extern crate rscam;
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use fltk::{
|
use fltk::{
|
||||||
app::App,
|
app::App,
|
||||||
enums::ColorDepth,
|
enums::ColorDepth,
|
||||||
frame::Frame,
|
frame::Frame,
|
||||||
image::RgbImage,
|
|
||||||
prelude::{GroupExt, WidgetBase, WidgetExt},
|
prelude::{GroupExt, WidgetBase, WidgetExt},
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
|
@ -25,8 +22,8 @@ fn main() {
|
||||||
// 配置摄像头参数
|
// 配置摄像头参数
|
||||||
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, 210), // 设置帧率为 30fps
|
interval: (1, 30), // 设置帧率为 30fps
|
||||||
resolution: (640, 400), // 设置分辨率为 640x480
|
resolution: (640, 480), // 设置分辨率为 640x480
|
||||||
format: b"MJPG", // 设置图像格式为 MJPG
|
format: b"MJPG", // 设置图像格式为 MJPG
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}) {
|
}) {
|
||||||
|
@ -35,26 +32,23 @@ fn main() {
|
||||||
eprint!("Open Camera Error:{}", e)
|
eprint!("Open Camera Error:{}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut w = 0 as i32;
|
|
||||||
let mut h = 0 as i32;
|
|
||||||
if camera_open {
|
if camera_open {
|
||||||
loop {
|
loop {
|
||||||
// 捕获一帧图像
|
// 捕获一帧图像
|
||||||
match camera.capture() {
|
match camera.capture() {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let start = Instant::now();
|
|
||||||
let img = image::load_from_memory(&data).unwrap();
|
let img = image::load_from_memory(&data).unwrap();
|
||||||
let rgb_data = img.to_rgb8();
|
let rgb_data = img.to_rgb8();
|
||||||
if w == 0 {
|
|
||||||
w = rgb_data.width() as i32;
|
let fltk_image = fltk::image::RgbImage::new(
|
||||||
h = rgb_data.height() as i32;
|
&rgb_data.as_raw(),
|
||||||
}
|
rgb_data.width() as i32,
|
||||||
let fltk_image =
|
rgb_data.height() as i32,
|
||||||
RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::Rgb8).unwrap();
|
ColorDepth::Rgb8,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
frame.set_image(Some(fltk_image));
|
frame.set_image(Some(fltk_image));
|
||||||
frame.redraw();
|
frame.redraw();
|
||||||
let duration = start.elapsed();
|
|
||||||
println!("Time elapsed in DrawImage is: {:?}", duration);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("捕获错误: {}", e);
|
eprintln!("捕获错误: {}", e);
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue