Run cargo fmt
This commit is contained in:
parent
a6077d755e
commit
2da9567679
2 changed files with 22 additions and 23 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
use nokhwa::Camera as NokhwaCamera;
|
|
||||||
use nokhwa::pixel_format::RgbFormat;
|
use nokhwa::pixel_format::RgbFormat;
|
||||||
use nokhwa::utils::{CameraIndex, RequestedFormat, RequestedFormatType};
|
use nokhwa::utils::{CameraIndex, RequestedFormat, RequestedFormatType};
|
||||||
|
use nokhwa::Camera as NokhwaCamera;
|
||||||
|
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
camera: NokhwaCamera,
|
camera: NokhwaCamera,
|
||||||
|
|
@ -12,12 +12,11 @@ impl Camera {
|
||||||
let index = CameraIndex::Index(camera_index);
|
let index = CameraIndex::Index(camera_index);
|
||||||
let format =
|
let format =
|
||||||
RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestResolution);
|
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")?;
|
camera.open_stream().context("failed to open stream")?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self { camera })
|
||||||
camera,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn capture(&mut self) -> Result<RgbImage> {
|
pub fn capture(&mut self) -> Result<RgbImage> {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use std::path::PathBuf;
|
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
mod camera;
|
||||||
mod gcode_stage;
|
mod gcode_stage;
|
||||||
mod openflexure_stage;
|
mod openflexure_stage;
|
||||||
mod camera;
|
|
||||||
|
|
||||||
mod stage_io;
|
mod stage_io;
|
||||||
|
use crate::camera::Camera;
|
||||||
use crate::stage_io::StageIO;
|
use crate::stage_io::StageIO;
|
||||||
use crate::xy_stage::XYStage;
|
use crate::xy_stage::XYStage;
|
||||||
use crate::camera::Camera;
|
|
||||||
|
|
||||||
mod xy_stage;
|
mod xy_stage;
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ struct CliArgs {
|
||||||
camera_index: u32,
|
camera_index: u32,
|
||||||
|
|
||||||
/// Directory all captured images are stored.
|
/// Directory all captured images are stored.
|
||||||
#[arg(long, value_name="out-dir")]
|
#[arg(long, value_name = "out-dir")]
|
||||||
output_directory: PathBuf,
|
output_directory: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,10 +47,8 @@ enum Backend {
|
||||||
GCode,
|
GCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_image(number: u32, pos: nalgebra::Vector3<f64>, dir: &PathBuf,
|
fn store_image(number: u32, pos: nalgebra::Vector3<f64>, dir: &PathBuf, img: &RgbImage) {
|
||||||
img: &RgbImage) {
|
let img_file = &dir.join(format!("img-{:05}-{:0},{:0}.png", number, pos[0], pos[1]));
|
||||||
let img_file =
|
|
||||||
&dir.join(format!("img-{:05}-{:0},{:0}.png", number, pos[0], pos[1]));
|
|
||||||
|
|
||||||
img.save(img_file).unwrap();
|
img.save(img_file).unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +83,9 @@ fn main() {
|
||||||
max_xy[2] = 0.0;
|
max_xy[2] = 0.0;
|
||||||
|
|
||||||
for n in 0..10 {
|
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());
|
store_image(n, origin, &args.output_directory, &cam.capture().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue