use crate::interface::camera::Camera;
use crate::interface::picture::Picture;
use crate::interface::video::Video;
enum SimpleImageInterfaceMode {
Camera,
Video,
Picture,
}
pub struct SimpleImageInterface {
mode: SimpleImageInterfaceMode,
camera: Option<Camera>,
picture: Option<Picture>,
video: Option<Video>,
}
impl SimpleImageInterface {
pub fn new_camera(device_: &str, width_: u32, height_: u32, fps_: u32) -> SimpleImageInterface {
SimpleImageInterface {
mode: SimpleImageInterfaceMode::Camera,
camera: Some(Camera::new(device_, width_, height_, fps_)),
picture: None,
video: None,
}
}
pub fn new_picture(image_path: impl Into<std::path::PathBuf>) -> SimpleImageInterface {
SimpleImageInterface {
mode: SimpleImageInterfaceMode::Picture,
camera: None,
picture: Some(Picture::new(image_path.into())),
video: None,
}
}
pub fn new_video(video_path: impl Into<std::path::PathBuf>) -> SimpleImageInterface {
SimpleImageInterface {
mode: SimpleImageInterfaceMode::Video,
camera: None,
picture: None,
video: Some(Video::new(video_path.into())),
}
}
pub fn get_frame(&mut self) -> Option<image::RgbImage> {
match self.mode {
SimpleImageInterfaceMode::Camera => self.camera.as_ref().unwrap().get_frame(),
SimpleImageInterfaceMode::Picture => self.picture.as_mut().unwrap().get_frame(),
SimpleImageInterfaceMode::Video => self.video.as_mut().unwrap().get_frame(),
}
}
}