aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--signature.cpp22
-rw-r--r--signature.hpp10
-rw-r--r--tests/testdrive.cpp5
3 files changed, 21 insertions, 16 deletions
diff --git a/signature.cpp b/signature.cpp
index a356102..fb4e8a3 100644
--- a/signature.cpp
+++ b/signature.cpp
@@ -8,6 +8,7 @@
* and
* libpuzzle (also an implementation of the article above).
*/
+#include "signature.hpp"
#include <algorithm>
#include <fstream>
@@ -21,7 +22,6 @@
#include "compressed_vector.hpp"
#include "imageutil.hpp"
-#include "signature.hpp"
static signature_config _default_cfg =
{
@@ -239,15 +239,15 @@ bool signature::operator==(const signature &o) const
return *p == *o.p;
}
-signature signature::from_preprocessed_matrix(cv::Mat m, const signature_config &cfg)
+signature signature::from_preprocessed_matrix(cv::Mat *m, const signature_config &cfg)
{
signature_priv *p = new signature_priv;
p->cfg = cfg;
if (cfg.crop)
- p->fimg = image_util::crop(m, cfg.contrast_threshold, cfg.max_cropping);
+ p->fimg = image_util::crop(*m, cfg.contrast_threshold, cfg.max_cropping);
else
- p->fimg = m;
+ p->fimg = *m;
if (cfg.blur_window > 1)
cv::blur(p->fimg, p->fimg, cv::Size(cfg.blur_window, cfg.blur_window));
p->get_light_charistics();
@@ -259,35 +259,35 @@ signature signature::from_preprocessed_matrix(cv::Mat m, const signature_config
return signature(p);
}
-signature signature::from_cvmatrix(cv::Mat m, const signature_config &cfg)
+signature signature::from_cvmatrix(cv::Mat *m, const signature_config &cfg)
{
cv::Mat ma, bw;
double sc = 1;
- switch (m.depth())
+ switch (m->depth())
{
case CV_8U: sc = 1. / 255; break;
case CV_16U: sc = 1. / 65535; break;
}
- m.convertTo(ma, CV_32F, sc);
- if (m.channels() == 4)
+ m->convertTo(ma, CV_32F, sc);
+ if (m->channels() == 4)
ma = image_util::blend_white(ma);
if (ma.channels() == 3)
cv::cvtColor(ma, bw, cv::COLOR_RGB2GRAY);
else
bw = ma;
- return signature::from_preprocessed_matrix(bw, cfg);
+ return signature::from_preprocessed_matrix(&bw, cfg);
}
signature signature::from_file(const char *fn, const signature_config &cfg)
{
cv::Mat img = cv::imread(fn, cv::IMREAD_UNCHANGED);
- return signature::from_cvmatrix(img, cfg);
+ return signature::from_cvmatrix(&img, cfg);
}
signature signature::from_path(const std::filesystem::path &path, const signature_config &cfg)
{
cv::Mat img = image_util::imread_path(path, cv::IMREAD_UNCHANGED);
- return signature::from_cvmatrix(img, cfg);
+ return signature::from_cvmatrix(&img, cfg);
}
signature_config signature::default_cfg()
diff --git a/signature.hpp b/signature.hpp
index e01a739..4e8c10f 100644
--- a/signature.hpp
+++ b/signature.hpp
@@ -5,7 +5,6 @@
#include <memory>
#include <filesystem>
-#include <opencv2/core.hpp>
struct signature_config
{
@@ -20,6 +19,11 @@ struct signature_config
double max_cropping;
};
+namespace cv
+{
+ class Mat;
+};
+
class signature_priv;
class signature
{
@@ -49,7 +53,7 @@ public:
* Then it will be passed to from_preprocessed_matrix.
* The matrix doesn't have to be continuous.
*/
- static signature from_cvmatrix(cv::Mat m, const signature_config &cfg);
+ static signature from_cvmatrix(cv::Mat *m, const signature_config &cfg);
/*
* Input must be a single channel, floating point matrix
@@ -58,7 +62,7 @@ public:
* STILL *Will* be cropped if config().crop == true
* STILL *Will* be blurred if config().blur_window > 1
*/
- static signature from_preprocessed_matrix(cv::Mat m, const signature_config &cfg);
+ static signature from_preprocessed_matrix(cv::Mat *m, const signature_config &cfg);
static signature_config default_cfg();
diff --git a/tests/testdrive.cpp b/tests/testdrive.cpp
index 1896cc8..d5cd7b3 100644
--- a/tests/testdrive.cpp
+++ b/tests/testdrive.cpp
@@ -209,7 +209,7 @@ void build_file_list(fs::path path, bool recursive, std::vector<fs::path> &out)
void job_func(int thid, size_t id)
{
cv::Mat img = image_util::imread_path(files[id], cv::IMREAD_UNCHANGED);
- signature s = signature::from_cvmatrix(img, cfg_full);
+ signature s = signature::from_cvmatrix(&img, cfg_full);
#if DEBUG > 1
s.dump();
#endif
@@ -223,7 +223,8 @@ 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)), cfg_subslice)));
+ cv::Mat slice = img(cv::Range(t, b), cv::Range(l, r));
+ subsigs.push_back(std::move(signature::from_cvmatrix(&slice, cfg_subslice)));
#if DEBUG > 0
printf("%ld, (%d, %d) %lu\n", id, i, j, signature_hash{}(subsigs.back()));
#endif