A visualisation of Viola-Jone's haar cascade algorithm.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

#[macro_use] extern crate log;
#[macro_use(s)] extern crate ndarray;
extern crate stopwatch;
use stopwatch::{Stopwatch};
use simplelog::*;
use v4l::{Buffer, CaptureDevice, MappedBufferStream};
use image;
mod visualhaar;
// use std::fs::File;
static mut CAMERA: Option<CaptureDevice> = None;
fn main() {
CombinedLogger::init(
vec![
TermLogger::new(LevelFilter::Info, Config::default(), TerminalMode::Mixed),
// WriteLogger::new(LevelFilter::Info, Config::default(), File::create("my_rust_binary.log").unwrap()),
]
).unwrap();
warn!("test");
let haar = visualhaar::HaarClassifier::from_xml("haarcascade_frontalface_alt2.xml").unwrap();
// println!("Haar: {:?}", haar);
let sw = Stopwatch::start_new();
let frame = image::open("/home/ruben/Documents/Projecten/2020/rust/lena_orig.png");
// let vec: Vec<u8> = frame.data().to_vec();
// Convert to Nannou ImageBuffer
// let img_buffer: Option<image::ImageBuffer<image::Rgb<u8>, Vec<u8>>> = image::ImageBuffer::from_raw(640,480, frame.data().to_vec());
match frame {
Err(e) => {
// no imagebuffer for this update. set haar outcomes to empy
error!("{:?}",e);
}
Ok(ib) => {
// let
// ib.map( nannou::image::DynamicImage::ImageRgb8);
// let ib_bw = nannou::image::imageops::grayscale(&ib);
// _model.image = Some(nannou::image::DynamicImage::ImageLuma8(ib_bw));
let i = ib.as_rgb8().unwrap().clone();
let image = haar.scan_image(i).unwrap().dynamic_img;
image.save("/home/ruben/Documents/Projecten/2020/rust/lena_orig-output.png");
info!("Scanning for faces took {}ms", sw.elapsed_ms());
// _model.image = Some(nannou::image::DynamicImage::ImageRgb8(ib));
}
}
}