Joshua Moerman
10 years ago
1 changed files with 51 additions and 0 deletions
@ -0,0 +1,51 @@ |
|||
#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; |
|||
}; |
Loading…
Reference in new issue