Files
image-similarity/src/bin/dctquery.rs
T
2024-05-17 13:43:18 +02:00

50 lines
1.2 KiB
Rust

//use image_similarity::descriptors::dct::DCT;
use image_similarity::descriptors::{DCT, Descriptor};
use image_similarity::store::DescriptorStore;
use std::env;
use log::{info, debug, error};
struct Cfg {
path: String
}
impl Cfg{
fn load(args: &[String]) -> Result<Cfg, &'static str> {
if args.len() < 2 {
return Err("Filename argument required");
}
let path = args[1].clone();
Ok(Cfg { path })
}
}
fn main() {
env_logger::init();
//Init all descriptors:
let desc = DCT::new().with_quality(50);
let args: Vec<String> = env::args().collect();
let cfg = Cfg::load(&args)
.expect("Error loading config");
let img = image::open(cfg.path)
.expect("Unable to open file");
println!("Iamge");
let conf = viuer::Config {
width: Some(16),
height: Some(8),
..Default::default()
};
viuer::print(&img, &conf).expect("Image printing failed.");
println!("Iamge");
let store =
DescriptorStore::new()
.with_file("store.messagepack");
//info!("{}", store);
let phash: u64 = desc.describe(&img);
info!("Phash integer:\n{phash}");
info!("Phash binary:\n{phash:064b}");
store.knn(phash, 10);
}