distance function
This commit is contained in:
@@ -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;
|
||||
|
||||
+7
-3
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user