diff --git a/src/descriptors.rs b/src/descriptors.rs index eca7118..d4b0e02 100644 --- a/src/descriptors.rs +++ b/src/descriptors.rs @@ -5,6 +5,9 @@ pub trait Descriptor { "Descriptor".to_string() } fn describe(&self, img: image::DynamicImage) -> u64; + fn distance(&self, a: u64, b: u64) -> u64 { + (a^b).count_ones().into() + } } pub struct Median; diff --git a/src/main.rs b/src/main.rs index 8df3dd6..168efd9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,11 @@ fn main() { let img0 = image::open("img/meowl.jpg").unwrap(); let img1 = image::open("img/nyameowl.jpg").unwrap(); let img2 = image::open("img/armmeowl.jpg").unwrap(); - println!("{:#x}", desc.describe(img0)); - println!("{:#x}", desc.describe(img1)); - println!("{:#x}", desc.describe(img2)); + let img0_phash = desc.describe(img0); + let img1_phash = desc.describe(img1); + let img2_phash = desc.describe(img2); + println!("{:#x}", img0_phash); + println!("{:#x}", img1_phash); + println!("{:#x}", img2_phash); + println!("meowl and armmeowl are {} different", desc.distance(img0_phash, img2_phash)); }