You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
#pragma once
|
|
|
|
#include <fingerprints.hpp>
|
|
#include <image_io.hpp>
|
|
|
|
#include <boost/serialization/access.hpp>
|
|
#include <boost/serialization/vector.hpp>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
template <typename Fingerprint, typename Traits = fingerprint_traits<Fingerprint>>
|
|
struct image_database {
|
|
using index = size_t;
|
|
|
|
static auto fingerprint_name() { return Fingerprint::name(); }
|
|
auto filename(index i) const { return filenames[i]; }
|
|
auto fingerprint(index i) const { return fingerprints[i]; }
|
|
auto size() const { return fingerprints.size(); }
|
|
|
|
void add(std::string const & filename){
|
|
auto && image = open_image(filename);
|
|
auto && fingerprint = Traits::calculate(image);
|
|
|
|
filenames.push_back(filename);
|
|
fingerprints.push_back(fingerprint);
|
|
}
|
|
|
|
//! returns a list of distances along with their index
|
|
auto distances_for_image(av::frame const & image) const {
|
|
std::vector<std::pair<typename Traits::distance_type, index>> ret;
|
|
ret.reserve(size());
|
|
|
|
auto const pre_fingerprint = Traits::pre_calculate(image);
|
|
for(auto&& fingerprint : fingerprints){
|
|
ret.emplace_back(Traits::distance(fingerprint, pre_fingerprint), ret.size());
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
private:
|
|
friend class boost::serialization::access;
|
|
template<class Archive>
|
|
void serialize(Archive & ar, const unsigned int /*version*/){
|
|
ar & filenames;
|
|
ar & fingerprints;
|
|
}
|
|
|
|
std::vector<std::string> filenames;
|
|
std::vector<Fingerprint> fingerprints;
|
|
};
|
|
|