diff --git a/Cargo.lock b/Cargo.lock index ec10b68..b24af28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bit_field" version = "0.10.1" @@ -234,6 +240,7 @@ dependencies = [ name = "image_similarity" version = "0.1.0" dependencies = [ + "base64", "image", "rmp-serde", "serde", diff --git a/Cargo.toml b/Cargo.toml index 60ffb63..f3a3851 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" image = "0.24.4" serde = "1.0.147" rmp-serde = "1.1.1" +base64 = "0.22.1" diff --git a/src/bin/dctfilename.rs b/src/bin/dctfilename.rs new file mode 100644 index 0000000..43392fe --- /dev/null +++ b/src/bin/dctfilename.rs @@ -0,0 +1,36 @@ +use image_similarity::descriptors::{Descriptor, DCT}; +use std::env; +use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}; + +struct Cfg { + path: String +} + +impl Cfg{ + fn load(args: &[String]) -> Result { + if args.len() < 2 { + return Err("Filename argument required"); + } + let path = args[1].clone(); + Ok(Cfg { path }) + } +} + +fn main() { + //Init all descriptors: + let desc = DCT; + + let args: Vec = env::args().collect(); + //dbg!(args); + + let cfg = Cfg::load(&args) + .expect("Error loading config"); + + let img = image::open(cfg.path) + .expect("Unable to open file"); + let phash: u64 = desc.describe(img); + println!("{phash}\n{phash:b}"); + let output = URL_SAFE_NO_PAD.encode(phash.to_be_bytes()); + println!("{output}") + +}