|
@ -25,9 +25,15 @@ pub struct PIHash<'a> { |
|
|
|
|
|
|
|
|
impl<'a> PIHash<'a> {
|
|
|
impl<'a> PIHash<'a> {
|
|
|
/**
|
|
|
/**
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
* Create a new pihash library, and initialize a cache of a path is passed.
|
|
|
* Create a new pihash library, and initialize a cache of a path is passed.
|
|
|
* If none is passed then no cache is initialized or used with the library
|
|
|
* If none is passed then no cache is initialized or used with the library
|
|
|
*/
|
|
|
*/
|
|
|
|
|
|
=======
|
|
|
|
|
|
* Create a new pihash library, and initialize a cache of a path is passed.
|
|
|
|
|
|
* If none is passed then no cache is initialized or used with the library
|
|
|
|
|
|
*/
|
|
|
|
|
|
>>>>>>> master
|
|
|
pub fn new(cache_path: Option<&'a str>) -> PIHash<'a> {
|
|
|
pub fn new(cache_path: Option<&'a str>) -> PIHash<'a> {
|
|
|
match cache_path {
|
|
|
match cache_path {
|
|
|
Some(path) => {
|
|
|
Some(path) => {
|
|
@ -212,8 +218,8 @@ mod tests { |
|
|
}
|
|
|
}
|
|
|
// println!("Name: {}", path.unwrap().path().display())
|
|
|
// println!("Name: {}", path.unwrap().path().display())
|
|
|
}
|
|
|
}
|
|
|
// Currently 12 images in the test imaages directory
|
|
|
|
|
|
assert!(num_paths == 12);
|
|
|
|
|
|
|
|
|
// Currently 12 images in the test images directory
|
|
|
|
|
|
assert_eq!(num_paths, 12);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -234,7 +240,7 @@ mod tests { |
|
|
image_path.to_str().unwrap(),
|
|
|
image_path.to_str().unwrap(),
|
|
|
image_hashes[index],
|
|
|
image_hashes[index],
|
|
|
calculated_hash);
|
|
|
calculated_hash);
|
|
|
assert!(calculated_hash == image_hashes[index]);
|
|
|
|
|
|
|
|
|
assert_eq!(calculated_hash, image_hashes[index]);
|
|
|
hashes[index] = calculated_hash;
|
|
|
hashes[index] = calculated_hash;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -244,8 +250,7 @@ mod tests { |
|
|
continue;
|
|
|
continue;
|
|
|
} else {
|
|
|
} else {
|
|
|
let distance = hash::calculate_hamming_distance(hashes[index], hashes[index2]);
|
|
|
let distance = hash::calculate_hamming_distance(hashes[index], hashes[index2]);
|
|
|
println!("Hashes [{}] and [{}] have a hamming distance of [{}] of a max \
|
|
|
|
|
|
allowed distance of [{}]",
|
|
|
|
|
|
|
|
|
println!("Hashes [{}] and [{}] have a hamming distance of [{}] of a max allowed distance of [{}]",
|
|
|
hashes[index],
|
|
|
hashes[index],
|
|
|
hashes[index2],
|
|
|
hashes[index2],
|
|
|
distance,
|
|
|
distance,
|
|
@ -291,9 +296,8 @@ mod tests { |
|
|
let sample_03_images: [&Path; 3] = [&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
let sample_03_images: [&Path; 3] = [&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
&Path::new("./test_images/sample_03_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_03_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_03_small.jpg")];
|
|
|
&Path::new("./test_images/sample_03_small.jpg")];
|
|
|
let sample_03_hashes: [u64; 3] = [135670932300497406,
|
|
|
|
|
|
135670932300497406,
|
|
|
|
|
|
135670932300497406];
|
|
|
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] =
|
|
|
|
|
|
[135670932300497406, 135670932300497406, 135670932300497406];
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
@ -356,9 +360,8 @@ mod tests { |
|
|
let sample_03_images: [&Path; 3] = [&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
let sample_03_images: [&Path; 3] = [&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
&Path::new("./test_images/sample_03_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_03_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_03_small.jpg")];
|
|
|
&Path::new("./test_images/sample_03_small.jpg")];
|
|
|
let sample_03_hashes: [u64; 3] = [262683193365159876,
|
|
|
|
|
|
225528496439353284,
|
|
|
|
|
|
225528496435158982];
|
|
|
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] =
|
|
|
|
|
|
[262683193365159876, 225528496439353284, 225528496435158982];
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
4u64,
|
|
|
4u64,
|
|
|