move experiment binary to folder
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
use image_similarity::descriptors::{Descriptor, Median, DCT};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod descriptors;
|
||||
+1
-35
@@ -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!")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user