use image_similarity::descriptors::{Descriptor, DCT}; use std::collections::HashMap; use std::fs; fn main() { env_logger::init(); let desc = DCT::new(); //Initialize hashmap, empty or from cached file: let count = fs::read_dir("img").unwrap().count(); let map_file = fs::read("map.messagepack"); let mut map: HashMap = match map_file { Ok(f) => rmp_serde::from_slice(&f).unwrap(), Err(_e) => HashMap::with_capacity(count), }; //Calculate phashes for all images for node in fs::read_dir("img").unwrap() { let file = node.expect("Error walking directory"); let name = file.file_name().into_string().expect("Issue with filename"); if !map.contains_key(&name) { let img = image::open(file.path()).expect("Unable to open file"); let phash = desc.describe(&img); map.insert(name, phash); } } for (key, val) in map.iter() { println!("{key: >15}: {val}\t {val:b}"); } //Serialize hashmap with MessagePack: let _serialized: Vec = rmp_serde::to_vec(&map).unwrap(); //fs::write("map.messagepack",&serialized).unwrap(); }