|
@ -17,8 +17,8 @@ use std::path::Path; |
|
|
|
|
|
|
|
|
use cache::Cache;
|
|
|
use cache::Cache;
|
|
|
|
|
|
|
|
|
pub mod hash;
|
|
|
|
|
|
pub mod cache;
|
|
|
pub mod cache;
|
|
|
|
|
|
pub mod hash;
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
#[repr(C)]
|
|
|
pub struct PIHash<'a> {
|
|
|
pub struct PIHash<'a> {
|
|
@ -49,40 +49,44 @@ impl<'a> PIHash<'a> { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_perceptual_hash(&self,
|
|
|
|
|
|
|
|
|
pub fn get_perceptual_hash(
|
|
|
|
|
|
&self,
|
|
|
path: &Path,
|
|
|
path: &Path,
|
|
|
precision: &hash::Precision,
|
|
|
precision: &hash::Precision,
|
|
|
hash_type: &hash::HashType)
|
|
|
|
|
|
-> u64 {
|
|
|
|
|
|
|
|
|
hash_type: &hash::HashType,
|
|
|
|
|
|
) -> u64 {
|
|
|
hash::get_perceptual_hash(&path, &precision, &hash_type, &self.cache)
|
|
|
hash::get_perceptual_hash(&path, &precision, &hash_type, &self.cache)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_phashes(&self, path: &'a Path) -> hash::PerceptualHashes {
|
|
|
pub fn get_phashes(&self, path: &'a Path) -> hash::PerceptualHashes {
|
|
|
hash::get_perceptual_hashes(&path,
|
|
|
|
|
|
&hash::Precision::Medium,
|
|
|
|
|
|
&self.cache)
|
|
|
|
|
|
|
|
|
hash::get_perceptual_hashes(&path, &hash::Precision::Medium, &self.cache)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_ahash(&self, path: &Path) -> u64 {
|
|
|
pub fn get_ahash(&self, path: &Path) -> u64 {
|
|
|
hash::get_perceptual_hash(&path,
|
|
|
|
|
|
|
|
|
hash::get_perceptual_hash(
|
|
|
|
|
|
&path,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::AHash,
|
|
|
&hash::HashType::AHash,
|
|
|
&self.cache)
|
|
|
|
|
|
|
|
|
&self.cache,
|
|
|
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_dhash(&self, path: &Path) -> u64 {
|
|
|
pub fn get_dhash(&self, path: &Path) -> u64 {
|
|
|
hash::get_perceptual_hash(&path,
|
|
|
|
|
|
|
|
|
hash::get_perceptual_hash(
|
|
|
|
|
|
&path,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::DHash,
|
|
|
&hash::HashType::DHash,
|
|
|
&self.cache)
|
|
|
|
|
|
|
|
|
&self.cache,
|
|
|
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn get_phash(&self, path: &Path) -> u64 {
|
|
|
pub fn get_phash(&self, path: &Path) -> u64 {
|
|
|
hash::get_perceptual_hash(&path,
|
|
|
|
|
|
|
|
|
hash::get_perceptual_hash(
|
|
|
|
|
|
&path,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::PHash,
|
|
|
&hash::HashType::PHash,
|
|
|
&self.cache)
|
|
|
|
|
|
|
|
|
&self.cache,
|
|
|
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -125,9 +129,11 @@ pub extern "C" fn ext_get_ahash(lib: &PIHash, path_char: *const libc::c_char) -> |
|
|
let image_path = match path_str.to_str() {
|
|
|
let image_path = match path_str.to_str() {
|
|
|
Ok(result) => result,
|
|
|
Ok(result) => result,
|
|
|
Err(e) => {
|
|
|
Err(e) => {
|
|
|
println!("Error: {}. Unable to parse '{}'",
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
"Error: {}. Unable to parse '{}'",
|
|
|
e,
|
|
|
e,
|
|
|
to_hex_string(path_str.to_bytes()));
|
|
|
|
|
|
|
|
|
to_hex_string(path_str.to_bytes())
|
|
|
|
|
|
);
|
|
|
panic!("Unable to parse path")
|
|
|
panic!("Unable to parse path")
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
@ -143,9 +149,11 @@ pub extern "C" fn ext_get_dhash(lib: &PIHash, path_char: *const libc::c_char) -> |
|
|
let image_path = match path_str.to_str() {
|
|
|
let image_path = match path_str.to_str() {
|
|
|
Ok(result) => result,
|
|
|
Ok(result) => result,
|
|
|
Err(e) => {
|
|
|
Err(e) => {
|
|
|
println!("Error: {}. Unable to parse '{}'",
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
"Error: {}. Unable to parse '{}'",
|
|
|
e,
|
|
|
e,
|
|
|
to_hex_string(path_str.to_bytes()));
|
|
|
|
|
|
|
|
|
to_hex_string(path_str.to_bytes())
|
|
|
|
|
|
);
|
|
|
panic!("Unable to parse path")
|
|
|
panic!("Unable to parse path")
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
@ -161,9 +169,11 @@ pub extern "C" fn ext_get_phash(lib: &PIHash, path_char: *const libc::c_char) -> |
|
|
let image_path = match path_str.to_str() {
|
|
|
let image_path = match path_str.to_str() {
|
|
|
Ok(result) => result,
|
|
|
Ok(result) => result,
|
|
|
Err(e) => {
|
|
|
Err(e) => {
|
|
|
println!("Error: {}. Unable to parse '{}'",
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
"Error: {}. Unable to parse '{}'",
|
|
|
e,
|
|
|
e,
|
|
|
to_hex_string(path_str.to_bytes()));
|
|
|
|
|
|
|
|
|
to_hex_string(path_str.to_bytes())
|
|
|
|
|
|
);
|
|
|
panic!("Unable to parse path")
|
|
|
panic!("Unable to parse path")
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
@ -186,9 +196,11 @@ pub extern "C" fn ext_get_phashes(lib: &PIHash, path_char: *const libc::c_char) |
|
|
let image_path = match path_str.to_str() {
|
|
|
let image_path = match path_str.to_str() {
|
|
|
Ok(result) => result,
|
|
|
Ok(result) => result,
|
|
|
Err(e) => {
|
|
|
Err(e) => {
|
|
|
println!("Error: {}. Unable to parse '{}'",
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
"Error: {}. Unable to parse '{}'",
|
|
|
e,
|
|
|
e,
|
|
|
to_hex_string(path_str.to_bytes()));
|
|
|
|
|
|
|
|
|
to_hex_string(path_str.to_bytes())
|
|
|
|
|
|
);
|
|
|
panic!("Unable to parse path")
|
|
|
panic!("Unable to parse path")
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
};
|
|
@ -209,7 +221,6 @@ pub extern "C" fn ext_free_phashes(raw_phashes: *const libc::c_void) { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn to_hex_string(bytes: &[u8]) -> String {
|
|
|
fn to_hex_string(bytes: &[u8]) -> String {
|
|
|
println!("length: {}", bytes.len());
|
|
|
println!("length: {}", bytes.len());
|
|
|
let mut strs: Vec<String> = Vec::new();
|
|
|
let mut strs: Vec<String> = Vec::new();
|
|
@ -230,9 +241,9 @@ mod tests { |
|
|
use cache;
|
|
|
use cache;
|
|
|
use hash;
|
|
|
use hash;
|
|
|
|
|
|
|
|
|
use super::PIHash;
|
|
|
|
|
|
#[cfg(feature = "bench")]
|
|
|
#[cfg(feature = "bench")]
|
|
|
use super::test::Bencher;
|
|
|
use super::test::Bencher;
|
|
|
|
|
|
use super::PIHash;
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn test_can_get_test_images() {
|
|
|
fn test_can_get_test_images() {
|
|
@ -263,21 +274,25 @@ mod tests { |
|
|
* Updated test function. Assumes 3 images to a set and no hamming distances.
|
|
|
* Updated test function. Assumes 3 images to a set and no hamming distances.
|
|
|
* We don't need to confirm that the hamming distance calculation works in these tests.
|
|
|
* We don't need to confirm that the hamming distance calculation works in these tests.
|
|
|
*/
|
|
|
*/
|
|
|
fn test_imageset_hash(hash_type: hash::HashType,
|
|
|
|
|
|
|
|
|
fn test_imageset_hash(
|
|
|
|
|
|
hash_type: hash::HashType,
|
|
|
hash_precision: hash::Precision,
|
|
|
hash_precision: hash::Precision,
|
|
|
max_hamming_distance: u64,
|
|
|
max_hamming_distance: u64,
|
|
|
image_paths: [&Path; 3],
|
|
|
image_paths: [&Path; 3],
|
|
|
image_hashes: [u64; 3],
|
|
|
image_hashes: [u64; 3],
|
|
|
lib: &PIHash) {
|
|
|
|
|
|
|
|
|
lib: &PIHash,
|
|
|
|
|
|
) {
|
|
|
let mut hashes: [u64; 3] = [0; 3];
|
|
|
let mut hashes: [u64; 3] = [0; 3];
|
|
|
for index in 0..image_paths.len() {
|
|
|
for index in 0..image_paths.len() {
|
|
|
let image_path = image_paths[index];
|
|
|
let image_path = image_paths[index];
|
|
|
let calculated_hash = lib.get_perceptual_hash(&image_path, &hash_precision, &hash_type);
|
|
|
let calculated_hash = lib.get_perceptual_hash(&image_path, &hash_precision, &hash_type);
|
|
|
println!("[{}] Image hashes for [{}] expected: [{}] actual: [{}]",
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
"[{}] Image hashes for [{}] expected: [{}] actual: [{}]",
|
|
|
hash_type,
|
|
|
hash_type,
|
|
|
image_path.to_str().unwrap(),
|
|
|
image_path.to_str().unwrap(),
|
|
|
image_hashes[index],
|
|
|
image_hashes[index],
|
|
|
calculated_hash);
|
|
|
|
|
|
|
|
|
calculated_hash
|
|
|
|
|
|
);
|
|
|
assert_eq!(calculated_hash, image_hashes[index]);
|
|
|
assert_eq!(calculated_hash, image_hashes[index]);
|
|
|
hashes[index] = calculated_hash;
|
|
|
hashes[index] = calculated_hash;
|
|
|
}
|
|
|
}
|
|
@ -308,65 +323,74 @@ mod tests { |
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_small.jpg")];
|
|
|
|
|
|
let sample_01_hashes: [u64; 3] = [
|
|
|
|
|
|
857051991849750,
|
|
|
|
|
|
857051991849750,
|
|
|
|
|
|
857051991849750];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_01_small.jpg"),
|
|
|
|
|
|
];
|
|
|
|
|
|
let sample_01_hashes: [u64; 3] = [857051991849750, 857051991849750, 857051991849750];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::AHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
|
sample_01_images,
|
|
|
sample_01_images,
|
|
|
sample_01_hashes,
|
|
|
sample_01_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_02 tests
|
|
|
// Sample_02 tests
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_02_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
18446744073441116160,
|
|
|
18446744073441116160,
|
|
|
18446744073441116160,
|
|
|
18446744073441116160,
|
|
|
18446744073441116160];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
|
|
|
|
|
|
18446744073441116160,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::AHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
3u64,
|
|
|
3u64,
|
|
|
sample_02_images,
|
|
|
sample_02_images,
|
|
|
sample_02_hashes,
|
|
|
sample_02_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_03 tests
|
|
|
// Sample_03 tests
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
&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")];
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] = [
|
|
|
|
|
|
135670932300497406,
|
|
|
|
|
|
135670932300497406,
|
|
|
|
|
|
135670932300497406];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_03_small.jpg"),
|
|
|
|
|
|
];
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] =
|
|
|
|
|
|
[135670932300497406, 135670932300497406, 135670932300497406];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::AHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
|
sample_03_images,
|
|
|
sample_03_images,
|
|
|
sample_03_hashes,
|
|
|
sample_03_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_04 tests
|
|
|
// Sample_04 tests
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_04_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
18446460933225054208,
|
|
|
18446460933225054208,
|
|
|
18446460933225054208,
|
|
|
18446460933225054208,
|
|
|
18446460933225054208];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::AHash,
|
|
|
|
|
|
|
|
|
18446460933225054208,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::AHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
0u64,
|
|
|
0u64,
|
|
|
sample_04_images,
|
|
|
sample_04_images,
|
|
|
sample_04_hashes,
|
|
|
sample_04_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Clean_Cache
|
|
|
// Clean_Cache
|
|
|
// super::teardown();
|
|
|
// super::teardown();
|
|
@ -381,65 +405,78 @@ mod tests { |
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_01_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_01_hashes: [u64; 3] = [
|
|
|
let sample_01_hashes: [u64; 3] = [
|
|
|
3404580580803739582,
|
|
|
3404580580803739582,
|
|
|
3404580580803739582,
|
|
|
3404580580803739582,
|
|
|
3404580580803739582];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
|
|
|
|
|
|
3404580580803739582,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::DHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
0u64,
|
|
|
0u64,
|
|
|
sample_01_images,
|
|
|
sample_01_images,
|
|
|
sample_01_hashes,
|
|
|
sample_01_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_02 tests
|
|
|
// Sample_02 tests
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_02_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
14726771606135242753,
|
|
|
14726771606135242753,
|
|
|
14726771606135242753,
|
|
|
14726771606135242753,
|
|
|
14726771606135242753];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
|
|
|
|
|
|
14726771606135242753,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::DHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
0u64,
|
|
|
0u64,
|
|
|
sample_02_images,
|
|
|
sample_02_images,
|
|
|
sample_02_hashes,
|
|
|
sample_02_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_03 tests
|
|
|
// Sample_03 tests
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
&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")];
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] = [
|
|
|
|
|
|
144115181601817086,
|
|
|
|
|
|
144115181601817086,
|
|
|
|
|
|
144115181601817086];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_03_small.jpg"),
|
|
|
|
|
|
];
|
|
|
|
|
|
let sample_03_hashes: [u64; 3] =
|
|
|
|
|
|
[144115181601817086, 144115181601817086, 144115181601817086];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::DHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
0u64,
|
|
|
0u64,
|
|
|
sample_03_images,
|
|
|
sample_03_images,
|
|
|
sample_03_hashes,
|
|
|
sample_03_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_04 tests
|
|
|
// Sample_04 tests
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_04_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
18374262188442386433,
|
|
|
18374262188442386433,
|
|
|
18374262188442386433,
|
|
|
18374262188442386433,
|
|
|
18374262188442386433];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::DHash,
|
|
|
|
|
|
|
|
|
18374262188442386433,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::DHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
|
sample_04_images,
|
|
|
sample_04_images,
|
|
|
sample_04_hashes,
|
|
|
sample_04_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Clean_Cache
|
|
|
// Clean_Cache
|
|
|
// super::teardown();
|
|
|
// super::teardown();
|
|
@ -454,65 +491,77 @@ mod tests { |
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
let sample_01_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_01_small.jpg")];
|
|
|
|
|
|
let sample_01_hashes: [u64; 3] = [
|
|
|
|
|
|
72357778504597504,
|
|
|
|
|
|
72357778504597504,
|
|
|
|
|
|
72357778504597504];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::PHash,
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_01_small.jpg"),
|
|
|
|
|
|
];
|
|
|
|
|
|
let sample_01_hashes: [u64; 3] = [72357778504597504, 72357778504597504, 72357778504597504];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::PHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
|
sample_01_images,
|
|
|
sample_01_images,
|
|
|
sample_01_hashes,
|
|
|
sample_01_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_02 tests
|
|
|
// Sample_02 tests
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
let sample_02_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_large.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_02_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_02_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
let sample_02_hashes: [u64; 3] = [
|
|
|
5332332327550844928,
|
|
|
5332332327550844928,
|
|
|
5332332327550844928,
|
|
|
5332332327550844928,
|
|
|
5332332327550844928];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::PHash,
|
|
|
|
|
|
|
|
|
5332332327550844928,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::PHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
1u64,
|
|
|
1u64,
|
|
|
sample_02_images,
|
|
|
sample_02_images,
|
|
|
sample_02_hashes,
|
|
|
sample_02_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_03 tests
|
|
|
// Sample_03 tests
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
let sample_03_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_03_large.jpg"),
|
|
|
&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] = [
|
|
|
let sample_03_hashes: [u64; 3] = [
|
|
|
6917529027641081856,
|
|
|
6917529027641081856,
|
|
|
6917529027641081856,
|
|
|
6917529027641081856,
|
|
|
6917529027641081856];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::PHash,
|
|
|
|
|
|
|
|
|
6917529027641081856,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::PHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
0u64,
|
|
|
0u64,
|
|
|
sample_03_images,
|
|
|
sample_03_images,
|
|
|
sample_03_hashes,
|
|
|
sample_03_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Sample_04 tests
|
|
|
// Sample_04 tests
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
let sample_04_images: [&Path; 3] = [
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_large.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_medium.jpg"),
|
|
|
&Path::new("./test_images/sample_04_small.jpg")];
|
|
|
|
|
|
|
|
|
&Path::new("./test_images/sample_04_small.jpg"),
|
|
|
|
|
|
];
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
let sample_04_hashes: [u64; 3] = [
|
|
|
10997931646002397184,
|
|
|
10997931646002397184,
|
|
|
10997931646002397184,
|
|
|
10997931646002397184,
|
|
|
10997931646002397184];
|
|
|
|
|
|
test_imageset_hash(hash::HashType::PHash,
|
|
|
|
|
|
|
|
|
10997931646002397184,
|
|
|
|
|
|
];
|
|
|
|
|
|
test_imageset_hash(
|
|
|
|
|
|
hash::HashType::PHash,
|
|
|
hash::Precision::Medium,
|
|
|
hash::Precision::Medium,
|
|
|
3u64,
|
|
|
3u64,
|
|
|
sample_04_images,
|
|
|
sample_04_images,
|
|
|
sample_04_hashes,
|
|
|
sample_04_hashes,
|
|
|
&lib);
|
|
|
|
|
|
|
|
|
&lib,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
// Clean_Cache
|
|
|
// Clean_Cache
|
|
|
// super::teardown();
|
|
|
// super::teardown();
|
|
@ -526,15 +575,19 @@ mod tests { |
|
|
|
|
|
|
|
|
// Setup the caches to make sure we're good to properly bench
|
|
|
// Setup the caches to make sure we're good to properly bench
|
|
|
// All phashes so that the matricies are pulled from cache as well
|
|
|
// All phashes so that the matricies are pulled from cache as well
|
|
|
lib.get_perceptual_hash(&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
|
|
|
|
|
|
lib.get_perceptual_hash(
|
|
|
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::PHash);
|
|
|
|
|
|
|
|
|
&hash::HashType::PHash,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
bench.iter(|| {
|
|
|
bench.iter(|| {
|
|
|
// Sample_01 Bench
|
|
|
// Sample_01 Bench
|
|
|
lib.get_perceptual_hash(&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
|
|
|
|
|
|
lib.get_perceptual_hash(
|
|
|
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::PHash);
|
|
|
|
|
|
|
|
|
&hash::HashType::PHash,
|
|
|
|
|
|
);
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -546,9 +599,11 @@ mod tests { |
|
|
|
|
|
|
|
|
bench.iter(|| {
|
|
|
bench.iter(|| {
|
|
|
// Sample_01 Bench
|
|
|
// Sample_01 Bench
|
|
|
lib.get_perceptual_hash(&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
|
|
|
|
|
|
lib.get_perceptual_hash(
|
|
|
|
|
|
&Path::new("./test_images/sample_01_large.jpg"),
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::Precision::Medium,
|
|
|
&hash::HashType::PHash);
|
|
|
|
|
|
|
|
|
&hash::HashType::PHash,
|
|
|
|
|
|
);
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|