From 137960a0261245a433f161d8fa4cbb53e4e50e6a Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 27 Aug 2022 22:36:28 -0400 Subject: Fix distance calculation. --- tests/signature_test.cpp | 4 ++-- tests/testdrive.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/signature_test.cpp b/tests/signature_test.cpp index 0b6b1f9..8d44431 100644 --- a/tests/signature_test.cpp +++ b/tests/signature_test.cpp @@ -5,8 +5,8 @@ int main() { std::vector a; - a.push_back(std::move(signature::from_file("img/x.jpg"))); - a.push_back(std::move(signature::from_file("img/z.jpg"))); + a.push_back(std::move(signature::from_file("img/x.jpg", signature::default_cfg()))); + a.push_back(std::move(signature::from_file("img/z.jpg", signature::default_cfg()))); for (size_t i = 0; i < a.size(); ++i) for (size_t j = 0; j < a.size(); ++j) { diff --git a/tests/testdrive.cpp b/tests/testdrive.cpp index c104e8a..b57d792 100644 --- a/tests/testdrive.cpp +++ b/tests/testdrive.cpp @@ -18,6 +18,8 @@ #include "thread_pool.hpp" +#define DEBUG 0 + int ctr; int recursive; int njobs=1; @@ -28,6 +30,32 @@ std::vector files; int nsliceh = 3; int nslicev = 3; +signature_config cfg_full = +{ + 9, //slices + 3, //blur_window + 2, //min_window + true, //crop + true, //comp + 0.5, //pr + 1./128,//noise_threshold + 0.05, //contrast_threshold + 0.25 //max_cropping +}; + +signature_config cfg_subslice = +{ + 4, //slices + 16, //blur_window + 2, //min_window + false, //crop + true, //comp + 0.5, //pr + 1./64, //noise_threshold + 0.05, //contrast_threshold + 0.25 //max_cropping +}; + struct sig_eq { bool operator()(const signature& a, const signature& b) const @@ -125,7 +153,12 @@ void build_file_list(std::filesystem::path path,bool recursive,std::vector 0 + printf("%ld, %s\n", out.size() - 1, out.back().c_str()); +#endif + } fclose(fp); } } @@ -139,7 +172,12 @@ void build_file_list(std::filesystem::path path,bool recursive,std::vector 0 + printf("%ld, %s\n", out.size() - 1, out.back().c_str()); +#endif + } fclose(fp); } } @@ -148,7 +186,10 @@ void build_file_list(std::filesystem::path path,bool recursive,std::vector 1 + s.dump(); +#endif int ssw = img.size().width / nsliceh; int ssh = img.size().height / nslicev; std::vector subsigs; @@ -159,7 +200,13 @@ void job_func(int thid, size_t id) int r = (i == nsliceh) ? img.size().width : (i + 1) * ssw; int t = j * ssh; int b = (j == nslicev) ? img.size().height : (j + 1) * ssh; - subsigs.push_back(std::move(signature::from_cvmatrix(img(cv::Range(t, b), cv::Range(l, r))))); + subsigs.push_back(std::move(signature::from_cvmatrix(img(cv::Range(t, b), cv::Range(l, r)), cfg_subslice))); +#if DEBUG > 0 + printf("%ld, (%d, %d) %lu\n", id, i, j, signature_hash{}(subsigs.back())); +#endif +#if DEBUG > 1 + subsigs.back().dump(); +#endif } printf("%d %lu\r", thid, id); @@ -177,6 +224,10 @@ void job_func(int thid, size_t id) { if (si.second == i) { +#if DEBUG > 1 + printf("%d@(%ld <-> %ld) %f\n", i, id, si.first, s.distance(signatures[si.first])); +#endif + if (!v[si.first] && s.distance(signatures[si.first]) < threshold) { out.emplace_back(id, std::move(si.first)); -- cgit v1.2.3