feat(main): 添加时间测量功能

This commit is contained in:
conglinyizhi 2024-12-07 10:01:17 +08:00
parent 7bf1618646
commit 33f0924adb
1 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,6 @@
extern crate rscam; extern crate rscam;
use std::time::Instant;
use fltk::{ use fltk::{
app::App, app::App,
enums::ColorDepth, enums::ColorDepth,
@ -23,8 +25,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, 30), // 设置帧率为 30fps interval: (1, 210), // 设置帧率为 30fps
resolution: (640, 480), // 设置分辨率为 640x480 resolution: (640, 400), // 设置分辨率为 640x480
format: b"MJPG", // 设置图像格式为 MJPG format: b"MJPG", // 设置图像格式为 MJPG
..Default::default() ..Default::default()
}) { }) {
@ -40,6 +42,7 @@ fn main() {
// 捕获一帧图像 // 捕获一帧图像
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 { if w == 0 {
@ -50,6 +53,8 @@ fn main() {
RgbImage::new(&rgb_data.as_raw(), w, h, ColorDepth::Rgb8).unwrap(); RgbImage::new(&rgb_data.as_raw(), w, h, 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);