#pragma once #include #include #include #include #include #include template > 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> 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 void serialize(Archive & ar, const unsigned int /*version*/){ ar & filenames; ar & fingerprints; } std::vector filenames; std::vector fingerprints; };