pub mod calibration;
pub use calibration::CameraCalibration;
use crate::error::Result;
use crate::image::Image;
use burn::tensor::backend::Backend;
pub enum CameraSource {
Index(usize),
String(String),
}
pub struct Camera<B: Backend> {
#[allow(dead_code)]
source: CameraSource,
device: B::Device,
is_opened: bool,
}
impl<B: Backend> Camera<B> {
pub fn open(source: CameraSource, device: &B::Device) -> Result<Self> {
Ok(Self {
source,
device: device.clone(),
is_opened: true,
})
}
pub fn capture(&mut self) -> Result<Image<B>> {
let w = 640;
let h = 480;
let flat_data = vec![0.5f32; 3 * h * w];
let tensor_data = burn::tensor::TensorData::new(flat_data, [3, h, w]);
let tensor = burn::tensor::Tensor::<B, 3>::from_data(tensor_data, &self.device);
Ok(Image::new(tensor))
}
pub fn is_opened(&self) -> bool {
self.is_opened
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_helpers::{TestBackend, test_device};
#[test]
fn test_camera_mock() {
let device = test_device();
let mut cam = Camera::<TestBackend>::open(CameraSource::Index(0), &device).unwrap();
assert!(cam.is_opened());
let frame = cam.capture().unwrap();
assert_eq!(frame.shape(), [3, 480, 640]);
}
}