diff --git a/src/bin/dctfilename.rs b/src/bin/dctfilename.rs index 4c42190..931ced6 100644 --- a/src/bin/dctfilename.rs +++ b/src/bin/dctfilename.rs @@ -31,7 +31,7 @@ fn main() { let img = image::open(cfg.path) .expect("Unable to open file"); - let phash: u64 = desc.describe(img); + let phash: u64 = desc.describe(&img); debug!("Phash integer:\n{phash}"); debug!("Phash binary:\n{phash:b}"); let output = URL_SAFE_NO_PAD.encode(phash.to_be_bytes()); diff --git a/src/descriptors/dct.rs b/src/descriptors/dct.rs index ab00797..1244af9 100644 --- a/src/descriptors/dct.rs +++ b/src/descriptors/dct.rs @@ -101,7 +101,7 @@ impl DCT { } impl Descriptor for DCT { - fn describe(&self, img: image::DynamicImage) -> u64 { + fn describe(&self, img: &image::DynamicImage) -> u64 { let resized = self.resize(img); let mut dct_values = self.dct(&resized); debug!("DCT-coefficients:\n {}", print_matrix(dct_values)); diff --git a/src/descriptors/mod.rs b/src/descriptors/mod.rs index 0c54c9d..fe0690f 100644 --- a/src/descriptors/mod.rs +++ b/src/descriptors/mod.rs @@ -2,10 +2,10 @@ pub trait Descriptor { fn info(&self) -> String { "Descriptor".to_string() } - fn resize(&self, img: image::DynamicImage) -> image::DynamicImage { + fn resize(&self, img: &image::DynamicImage) -> image::DynamicImage { img.grayscale().thumbnail_exact(8, 8) } - fn describe(&self, img: image::DynamicImage) -> u64; + fn describe(&self, img: &image::DynamicImage) -> u64; fn distance(&self, a: u64, b: u64) -> u64 { (a^b).count_ones().into() } diff --git a/src/store.rs b/src/store.rs index 63ae6dc..04a6029 100644 --- a/src/store.rs +++ b/src/store.rs @@ -75,7 +75,7 @@ impl DescriptorStore { continue } }; - let phash = desc.describe(img); + let phash = desc.describe(&img); self.map.insert(name, phash); } else { debug!("{} already known, skipping.", name);