 |
AliceVision
Photogrammetric Computer Vision Framework
|
9 #include "VocabularyTree.hpp"
10 #include <aliceVision/types.hpp>
26 DocId
id{UndefinedIndexT};
38 bool operator==(
const DocMatch& other)
const {
return id == other.id && score == other.score; }
39 bool operator!=(
const DocMatch& other)
const {
return !(*
this == other); }
42 typedef std::vector<DocMatch> DocMatches;
44 std::ostream& operator<<(std::ostream& os,
const DocMatches& matches);
59 explicit Database(uint32_t num_words = 0);
68 DocId
insert(DocId doc_id,
const SparseHistogram& document);
77 void sanityCheck(std::size_t N, std::map<std::size_t, DocMatches>& matches)
const;
87 void find(
const std::vector<Word>& document,
89 std::vector<DocMatch>& matches,
90 const std::string& distanceMethod =
"strongCommonPoints")
const;
100 void find(
const SparseHistogram& query,
102 std::vector<DocMatch>& matches,
103 const std::string& distanceMethod =
"strongCommonPoints")
const;
117 std::size_t
size()
const;
128 const SparseHistogramPerImage& getSparseHistogramPerImage()
const {
return database_; }
136 WordFrequency() =
default;
137 WordFrequency(DocId _id, uint32_t _count)
144 typedef std::vector<WordFrequency> InvertedFile;
149 friend std::ostream&
operator<<(std::ostream& os,
const SparseHistogram& dv);
151 std::vector<InvertedFile> word_files_;
152 std::vector<float> word_weights_;
153 SparseHistogramPerImage database_;
159 void normalize(SparseHistogram& v)
const;
DocId insert(DocId doc_id, const SparseHistogram &document)
Insert a new document.
Definition: Database.cpp:45
friend std::ostream & operator<<(std::ostream &os, const SparseHistogram &dv)
Definition: Database.cpp:19
void computeTfIdfWeights(float default_weight=1.0f)
Compute the TF-IDF weights of all the words. To be called after inserting a corpus of training exampl...
Definition: Database.cpp:145
std::size_t size() const
Return the size of the database in terms of number of documents.
Definition: Database.cpp:206
Struct representing a single database match.
Definition: Database.hpp:24
Definition: checkerDetector.cpp:32
void find(const std::vector< Word > &document, std::size_t N, std::vector< DocMatch > &matches, const std::string &distanceMethod="strongCommonPoints") const
Find the top N matches in the database for the query document.
Definition: Database.cpp:105
void sanityCheck(std::size_t N, std::map< std::size_t, DocMatches > &matches) const
Perform a sanity check of the database by querying each document of the database and finding its top ...
Definition: Database.cpp:66
Database(uint32_t num_words=0)
Constructor.
Definition: Database.cpp:40
Class for efficiently matching a bag-of-words representation of a document (image) against a database...
Definition: Database.hpp:50
bool operator<(const DocMatch &other) const
Allows sorting DocMatches in best-to-worst order with std::sort.
Definition: Database.hpp:36
void loadWeights(const std::string &file)
Load the vocabulary word weights from a file.
Definition: Database.cpp:167
void saveWeights(const std::string &file) const
Save the vocabulary word weights to a file.
Definition: Database.cpp:159