Run cargo fmt

This commit is contained in:
Henner Zeller 2026-03-08 20:38:48 +01:00
parent a6077d755e
commit 2da9567679
2 changed files with 22 additions and 23 deletions

View file

@ -1,8 +1,8 @@
use anyhow::{Context, Result};
use image::RgbImage;
use nokhwa::Camera as NokhwaCamera;
use nokhwa::pixel_format::RgbFormat;
use nokhwa::utils::{CameraIndex, RequestedFormat, RequestedFormatType};
use nokhwa::Camera as NokhwaCamera;
pub struct Camera {
camera: NokhwaCamera,
@ -12,12 +12,11 @@ impl Camera {
let index = CameraIndex::Index(camera_index);
let format =
RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestResolution);
let mut camera = NokhwaCamera::new(index, format).context("could not find/access webcam")?;
let mut camera =
NokhwaCamera::new(index, format).context("could not find/access webcam")?;
camera.open_stream().context("failed to open stream")?;
Ok(Self {
camera,
})
Ok(Self { camera })
}
pub fn capture(&mut self) -> Result<RgbImage> {

View file

@ -1,15 +1,15 @@
use clap::{Parser, ValueEnum};
use std::path::PathBuf;
use image::RgbImage;
use std::path::PathBuf;
mod camera;
mod gcode_stage;
mod openflexure_stage;
mod camera;
mod stage_io;
use crate::camera::Camera;
use crate::stage_io::StageIO;
use crate::xy_stage::XYStage;
use crate::camera::Camera;
mod xy_stage;
@ -33,7 +33,7 @@ struct CliArgs {
camera_index: u32,
/// Directory all captured images are stored.
#[arg(long, value_name="out-dir")]
#[arg(long, value_name = "out-dir")]
output_directory: PathBuf,
}
@ -47,10 +47,8 @@ enum Backend {
GCode,
}
fn store_image(number: u32, pos: nalgebra::Vector3<f64>, dir: &PathBuf,
img: &RgbImage) {
let img_file =
&dir.join(format!("img-{:05}-{:0},{:0}.png", number, pos[0], pos[1]));
fn store_image(number: u32, pos: nalgebra::Vector3<f64>, dir: &PathBuf, img: &RgbImage) {
let img_file = &dir.join(format!("img-{:05}-{:0},{:0}.png", number, pos[0], pos[1]));
img.save(img_file).unwrap();
}
@ -85,7 +83,9 @@ fn main() {
max_xy[2] = 0.0;
for n in 0..10 {
stage.move_absolute_cartesian(max_xy * n as f64 / 10.0).unwrap();
stage
.move_absolute_cartesian(max_xy * n as f64 / 10.0)
.unwrap();
store_image(n, origin, &args.output_directory, &cam.capture().unwrap());
}
}