move experiment binary to folder

This commit is contained in:
2024-05-04 10:57:22 +02:00
parent 08dd17f292
commit 3c861cb796
3 changed files with 37 additions and 35 deletions
+1 -35
View File
@@ -1,37 +1,3 @@
use descriptors::{Descriptor, Median, DCT};
use std::collections::HashMap;
use std::fs;
pub mod descriptors;
fn main() {
//Init all descriptors:
let desc = Median;
//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<String, u64> = 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<u8> = rmp_serde::to_vec(&map).unwrap();
//fs::write("map.messagepack",&serialized).unwrap();
print!("Hello world!")
}