use log::info;
pub struct Camera {
camera: rscam::Camera,
width: u32,
height: u32,
}
impl Camera {
pub fn new(device_: &str, width_: u32, height_: u32, fps_: u32) -> Camera {
let mut camera_ = rscam::new(device_).unwrap();
camera_
.start(&rscam::Config {
interval: (1, fps_),
resolution: (width_, height_),
format: b"RGB3",
..Default::default()
})
.unwrap();
info!("Camera {}: {} * {}, {} fps", device_, width_, height_, fps_);
Camera {
camera: camera_,
width: width_,
height: height_,
}
}
pub fn get_frame(&self) -> Option<image::RgbImage> {
let frame: rscam::Frame = self.camera.capture().unwrap();
let rgb_image =
image::RgbImage::from_vec(self.width, self.height, (&frame[..]).to_vec()).unwrap();
Some(rgb_image)
}
}