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.

67 lines
2.2 KiB

#[macro_use] extern crate log;
#[macro_use(s)] extern crate ndarray;
extern crate stopwatch;
use stopwatch::{Stopwatch};
use simplelog::*;
use image;
mod visualhaar;
mod heatmap;
// use std::fs::File;
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 frame = image::open("test.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 hm = Some(heatmap::Heatmap::new(heatmap::ColorMaps::Plasma));
let mut sw = Stopwatch::start_new();
let image = haar.scan_image(i, &hm, 4).unwrap().dynamic_img;
info!("Scanning for faces took {}ms", sw.elapsed_ms());
image.save("test-output.png");
// let hm = heatmap::Heatmap::new(heatmap::ColorMaps::NipySpectral);
// let hm = heatmap::Heatmap::new(heatmap::ColorMaps::TraficLight);
// sw.restart();
// let hm = h;
// let image_hm = hm.convert_image(image);
// image_hm.save("/home/ruben/Documents/Projecten/2020/rust/lena_orig-output-hm.png");
// info!("Generating Heatmap {}ms", sw.elapsed_ms());
// _model.image = Some(nannou::image::DynamicImage::ImageRgb8(ib));
}
}
}