AliceVision
Photogrammetric Computer Vision Framework
Classes | Public Member Functions | Friends | List of all members
aliceVision::voctree::Database Class Reference

Class for efficiently matching a bag-of-words representation of a document (image) against a database of known documents. More...

#include <Database.hpp>

Public Member Functions

 Database (uint32_t num_words=0)
 Constructor. More...
 
DocId insert (DocId doc_id, const SparseHistogram &document)
 Insert a new document. More...
 
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 N matches. More...
 
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. More...
 
void find (const SparseHistogram &query, 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. More...
 
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 examples into the database. More...
 
std::size_t size () const
 Return the size of the database in terms of number of documents. More...
 
void saveWeights (const std::string &file) const
 Save the vocabulary word weights to a file.
 
void loadWeights (const std::string &file)
 Load the vocabulary word weights from a file.
 
const SparseHistogramPerImage & getSparseHistogramPerImage () const
 

Friends

std::ostream & operator<< (std::ostream &os, const SparseHistogram &dv)
 

Detailed Description

Class for efficiently matching a bag-of-words representation of a document (image) against a database of known documents.

Constructor & Destructor Documentation

◆ Database()

aliceVision::voctree::Database::Database ( uint32_t  num_words = 0)
explicit

Constructor.

If computing weights for a new vocabulary, num_words should be the size of the vocabulary. If calling loadWeights(), it can be left zero.

Member Function Documentation

◆ computeTfIdfWeights()

void aliceVision::voctree::Database::computeTfIdfWeights ( float  default_weight = 1.0f)

Compute the TF-IDF weights of all the words. To be called after inserting a corpus of training examples into the database.

Parameters
default_weightThe default weight of a word that appears in none of the training documents.

◆ find() [1/2]

void aliceVision::voctree::Database::find ( const SparseHistogram &  query,
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.

Parameters
[in]queryThe query document, a normalized set of quantized words.
[int]N The number of matches to return.
[in]distanceMethoddistance method (norm L1, etc.)
[out]matchesIDs and scores for the top N matching database documents.
queryThe query document, a normalized set of quantized words.
NThe number of matches to return.
[out]matchesIDs and scores for the top N matching database documents.
[in]distanceMethodthe method used to compute distance between histograms.

◆ find() [2/2]

void aliceVision::voctree::Database::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.

Parameters
[in]documentThe query document, a set of quantized words.
[in]NThe number of matches to return.
[in]distanceMethoddistance method (norm L1, etc.)
[out]matchesIDs and scores for the top N matching database documents.
[in]documentThe query document, a set of quantized words.
[in]NThe number of matches to return.
[out]matchesIDs and scores for the top N matching database documents.
[in]distanceMethodthe method used to compute distance between histograms.

◆ insert()

DocId aliceVision::voctree::Database::insert ( DocId  doc_id,
const SparseHistogram &  document 
)

Insert a new document.

Parameters
doc_idUnique ID of the new document to insert
documentThe set of quantized words in a document/image.
Returns
An ID representing the inserted document.

◆ sanityCheck()

void aliceVision::voctree::Database::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 N matches.

Parameters
[in]NThe number of matches to return.
[out]matchesIDs and scores for the top N matching database documents.

◆ size()

std::size_t aliceVision::voctree::Database::size ( ) const

Return the size of the database in terms of number of documents.

‍**

Returns
the number of documents

Return the size of the database in terms of number of documents

Returns
the number of documents

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const SparseHistogram &  dv 
)
friend
Todo:
Use sorted vector?

The documentation for this class was generated from the following files: