Using nokhwa
xxxxxxxxxx
use nokhwa::Camera;use nokhwa::utils;
use std::fs::File; //For saving images to files to test
use std::io::prelude::*; //For saving images to files to test
fn main() {
// first camera in system
let camera_index = utils::CameraIndex::Index(0);
// request the absolute highest resolution CameraFormat that can be decoded to RGB.
let requested = utils::RequestedFormat::new::<nokhwa::pixel_format::RgbFormat>(nokhwa::utils::RequestedFormatType::AbsoluteHighestFrameRate);
// make the camera
let mut camera = match Camera::new(camera_index, requested){
Ok(t) => {t},
Err(e) => {println!("Camera creation error:\n{}", e);
return;},
};
// get a frame
let frame = camera.frame().unwrap();
println!("Captured Single Frame of {}", frame.buffer().len());
// Save image to check
let mut file = File::create("test.jpg").unwrap();
file.write_all(frame.buffer());
}
https://doc.rust-lang.org/std/fs/struct.File.html
https://stackoverflow.com/questions/38886081/how-to-save-a-png-image-in-rust