Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
DBoW2::TemplatedVocabulary< TDescriptor, F > Class Template Reference

Generic Vocabulary. More...

#include <TemplatedVocabulary.h>

Classes

struct  Node
 Tree node. More...
 

Public Member Functions

virtual void create (const std::vector< std::vector< TDescriptor > > &training_features)
 
virtual void create (const std::vector< std::vector< TDescriptor > > &training_features, int k, int L)
 
virtual void create (const std::vector< std::vector< TDescriptor > > &training_features, int k, int L, WeightingType weighting, ScoringType scoring)
 
virtual bool empty () const
 
int getBranchingFactor () const
 
int getDepthLevels () const
 
float getEffectiveLevels () const
 
virtual NodeId getParentNode (WordId wid, int levelsup) const
 
ScoringType getScoringType () const
 
WeightingType getWeightingType () const
 
virtual TDescriptor getWord (WordId wid) const
 
void getWordsFromNode (NodeId nid, std::vector< WordId > &words) const
 
virtual WordValue getWordWeight (WordId wid) const
 
void load (const std::string &filename)
 
virtual void load (const cv::FileStorage &fs, const std::string &name="vocabulary")
 
bool loadFromTextFile (const std::string &filename)
 
TemplatedVocabulary< TDescriptor, F > & operator= (const TemplatedVocabulary< TDescriptor, F > &voc)
 
void save (const std::string &filename) const
 
virtual void save (cv::FileStorage &fs, const std::string &name="vocabulary") const
 
void saveToTextFile (const std::string &filename) const
 
double score (const BowVector &a, const BowVector &b) const
 
void setScoringType (ScoringType type)
 
void setWeightingType (WeightingType type)
 
virtual unsigned int size () const
 
virtual int stopWords (double minWeight)
 
 TemplatedVocabulary (int k=10, int L=5, WeightingType weighting=TF_IDF, ScoringType scoring=L1_NORM)
 
 TemplatedVocabulary (const std::string &filename)
 
 TemplatedVocabulary (const char *filename)
 
 TemplatedVocabulary (const TemplatedVocabulary< TDescriptor, F > &voc)
 
virtual void transform (const std::vector< TDescriptor > &features, BowVector &v) const
 
virtual void transform (const std::vector< TDescriptor > &features, BowVector &v, FeatureVector &fv, int levelsup) const
 
virtual WordId transform (const TDescriptor &feature) const
 
virtual ~TemplatedVocabulary ()
 

Protected Types

typedef const TDescriptor * pDescriptor
 Pointer to descriptor. More...
 

Protected Member Functions

void createScoringObject ()
 
void createWords ()
 
void getFeatures (const vector< vector< TDescriptor > > &training_features, vector< pDescriptor > &features) const
 
void HKmeansStep (NodeId parent_id, const vector< pDescriptor > &descriptors, int current_level)
 
virtual void initiateClusters (const vector< pDescriptor > &descriptors, vector< TDescriptor > &clusters) const
 
void initiateClustersKMpp (const vector< pDescriptor > &descriptors, vector< TDescriptor > &clusters) const
 
void setNodeWeights (const vector< vector< TDescriptor > > &features)
 
virtual void transform (const TDescriptor &feature, WordId &id, WordValue &weight, NodeId *nid=NULL, int levelsup=0) const
 
virtual void transform (const TDescriptor &feature, WordId &id) const
 

Protected Attributes

int m_k
 Branching factor. More...
 
int m_L
 Depth levels. More...
 
std::vector< Nodem_nodes
 Tree nodes. More...
 
ScoringType m_scoring
 Scoring method. More...
 
GeneralScoringm_scoring_object
 Object for computing scores. More...
 
WeightingType m_weighting
 Weighting method. More...
 
std::vector< Node * > m_words
 

Detailed Description

template<class TDescriptor, class F>
class DBoW2::TemplatedVocabulary< TDescriptor, F >

Generic Vocabulary.

Parameters
TDescriptorclass of descriptor
Fclass of descriptor functions

Definition at line 44 of file TemplatedVocabulary.h.

Member Typedef Documentation

template<class TDescriptor, class F>
typedef const TDescriptor* DBoW2::TemplatedVocabulary< TDescriptor, F >::pDescriptor
protected

Pointer to descriptor.

Definition at line 294 of file TemplatedVocabulary.h.

Constructor & Destructor Documentation

template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( int  k = 10,
int  L = 5,
WeightingType  weighting = TF_IDF,
ScoringType  scoring = L1_NORM 
)

Initiates an empty vocabulary

Parameters
kbranching factor
Ldepth levels
weightingweighting type
scoringscoring type

Definition at line 435 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( const std::string &  filename)

Creates the vocabulary by loading a file

Parameters
filename

Definition at line 446 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( const char *  filename)

Creates the vocabulary by loading a file

Parameters
filename

Definition at line 455 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( const TemplatedVocabulary< TDescriptor, F > &  voc)

Copy constructor

Parameters
voc

Definition at line 517 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::~TemplatedVocabulary ( )
virtual

Destructor

Definition at line 527 of file TemplatedVocabulary.h.

Member Function Documentation

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create ( const std::vector< std::vector< TDescriptor > > &  training_features)
virtual

Creates a vocabulary from the training features with the already defined parameters

Parameters
training_features

Definition at line 558 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create ( const std::vector< std::vector< TDescriptor > > &  training_features,
int  k,
int  L 
)
virtual

Creates a vocabulary from the training features, setting the branching factor and the depth levels of the tree

Parameters
training_features
kbranching factor
Ldepth levels

Definition at line 592 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create ( const std::vector< std::vector< TDescriptor > > &  training_features,
int  k,
int  L,
WeightingType  weighting,
ScoringType  scoring 
)
virtual

Creates a vocabulary from the training features, setting the branching factor nad the depth levels of the tree, and the weighting and scoring schemes

Definition at line 605 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::createScoringObject ( )
protected

Creates an instance of the scoring object accoring to m_scoring

Definition at line 463 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::createWords ( )
protected

Create the words of the vocabulary once the tree has been built

Definition at line 918 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::empty ( ) const
inlinevirtual

Returns whether the vocabulary is empty (i.e. it has not been trained)

Returns
true iff the vocabulary is empty

Definition at line 1009 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
int DBoW2::TemplatedVocabulary< TDescriptor, F >::getBranchingFactor ( ) const
inline

Returns the branching factor of the tree (k)

Returns
k

Definition at line 185 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
int DBoW2::TemplatedVocabulary< TDescriptor, F >::getDepthLevels ( ) const
inline

Returns the depth levels of the tree (L)

Returns
L

Definition at line 191 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
float DBoW2::TemplatedVocabulary< TDescriptor, F >::getEffectiveLevels ( ) const

Returns the real depth levels of the tree on average

Returns
average of depth levels of leaves

Definition at line 1017 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getFeatures ( const vector< vector< TDescriptor > > &  training_features,
vector< pDescriptor > &  features 
) const
protected

Returns a set of pointers to descriptores

Parameters
training_featuresall the features
features(out) pointers to the training features

Definition at line 621 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
NodeId DBoW2::TemplatedVocabulary< TDescriptor, F >::getParentNode ( WordId  wid,
int  levelsup 
) const
virtual

Returns the id of the node that is "levelsup" levels from the word given

Parameters
widword id
levelsup0..L
Returns
node id. if levelsup is 0, returns the node id associated to the word id

Definition at line 1265 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
ScoringType DBoW2::TemplatedVocabulary< TDescriptor, F >::getScoringType ( ) const
inline

Returns the scoring method

Returns
scoring method

Definition at line 223 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
WeightingType DBoW2::TemplatedVocabulary< TDescriptor, F >::getWeightingType ( ) const
inline

Returns the weighting method

Returns
weighting method

Definition at line 217 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
TDescriptor DBoW2::TemplatedVocabulary< TDescriptor, F >::getWord ( WordId  wid) const
inlinevirtual

Returns the descriptor of a word

Parameters
widword id
Returns
descriptor

Definition at line 1034 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordsFromNode ( NodeId  nid,
std::vector< WordId > &  words 
) const

Returns the ids of all the words that are under the given node id, by traversing any of the branches that goes down from the node

Parameters
nidstarting node id
wordsids of words

Definition at line 1280 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
WordValue DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordWeight ( WordId  wid) const
inlinevirtual

Returns the weight of a word

Parameters
widword id
Returns
weight

Definition at line 1042 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::HKmeansStep ( NodeId  parent_id,
const vector< pDescriptor > &  descriptors,
int  current_level 
)
protected

Creates a level in the tree, under the parent, by running kmeans with a descriptor set, and recursively creates the subsequent levels too

Parameters
parent_idid of parent node
descriptorsdescriptors to run the kmeans on
current_levelcurrent level in the tree

Definition at line 642 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClusters ( const vector< pDescriptor > &  descriptors,
vector< TDescriptor > &  clusters 
) const
protectedvirtual

Creates k clusters from the given descriptors with some seeding algorithm.

Note
In this class, kmeans++ is used, but this function should be overriden by inherited classes.

Definition at line 825 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClustersKMpp ( const vector< pDescriptor > &  descriptors,
vector< TDescriptor > &  clusters 
) const
protected

Creates k clusters from the given descriptor sets by running the initial step of kmeans++

Parameters
descriptors
clustersresulting clusters

Definition at line 833 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load ( const std::string &  filename)

Loads the vocabulary from a file

Parameters
filename

Definition at line 1465 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load ( const cv::FileStorage &  fs,
const std::string &  name = "vocabulary" 
)
virtual

Loads the vocabulary from a file storage node

Parameters
fnfirst node
subnamename of the child node of fn where the tree is stored. If not given, the fn node is used instead

Definition at line 1573 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::loadFromTextFile ( const std::string &  filename)

Loads the vocabulary from a text file

Parameters
filename

Definition at line 1338 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
TemplatedVocabulary< TDescriptor, F > & DBoW2::TemplatedVocabulary< TDescriptor, F >::operator= ( const TemplatedVocabulary< TDescriptor, F > &  voc)

Assigns the given vocabulary to this by copying its data and removing all the data contained by this vocabulary before

Parameters
voc
Returns
reference to this vocabulary

Definition at line 537 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save ( const std::string &  filename) const

Saves the vocabulary into a file

Parameters
filename

Definition at line 1454 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save ( cv::FileStorage &  fs,
const std::string &  name = "vocabulary" 
) const
virtual

Saves the vocabulary to a file storage structure

Parameters
fnnode in file storage

Definition at line 1476 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::saveToTextFile ( const std::string &  filename) const

Saves the vocabulary into a text file

Parameters
filename

Definition at line 1429 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
double DBoW2::TemplatedVocabulary< TDescriptor, F >::score ( const BowVector a,
const BowVector b 
) const
inline

Returns the score of two vectors

Parameters
avector
bvector
Returns
score between vectors
Note
the vectors must be already sorted and normalized if necessary

Definition at line 1200 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setNodeWeights ( const vector< vector< TDescriptor > > &  features)
protected

Sets the weights of the nodes of tree according to the given features. Before calling this function, the nodes and the words must be already created (by calling HKmeansStep and createWords)

Parameters
features

Definition at line 944 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setScoringType ( ScoringType  type)

Changes the scoring method

Parameters
typenew scoring type

Definition at line 500 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setWeightingType ( WeightingType  type)
inline

Changes the weighting method

Parameters
typenew weighting type

Definition at line 509 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
unsigned int DBoW2::TemplatedVocabulary< TDescriptor, F >::size ( ) const
inlinevirtual

Returns the number of words in the vocabulary

Returns
number of words

Definition at line 1001 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
int DBoW2::TemplatedVocabulary< TDescriptor, F >::stopWords ( double  minWeight)
virtual

Stops those words whose weight is below minWeight. Words are stopped by setting their weight to 0. There are not returned later when transforming image features into vectors. Note that when using IDF or TF_IDF, the weight is the idf part, which is equivalent to -log(f), where f is the frequency of the word (f = Ni/N, Ni: number of training images where the word is present, N: number of training images). Note that the old weight is forgotten, and subsequent calls to this function with a lower minWeight have no effect.

Returns
number of words stopped now

Definition at line 1320 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const std::vector< TDescriptor > &  features,
BowVector v 
) const
virtual

Transforms a set of descriptores into a bow vector

Parameters
features
v(out) bow vector of weighted words

Definition at line 1066 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const std::vector< TDescriptor > &  features,
BowVector v,
FeatureVector fv,
int  levelsup 
) const
virtual

Transform a set of descriptors into a bow vector and a feature vector

Parameters
features
v(out) bow vector
fv(out) feature vector of nodes and feature indexes
levelsuplevels to go up the vocabulary tree to get the node index

Definition at line 1127 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
WordId DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const TDescriptor &  feature) const
virtual

Transforms a single feature into a word (without weight)

Parameters
feature
Returns
word id

Definition at line 1051 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const TDescriptor &  feature,
WordId id,
WordValue weight,
NodeId nid = NULL,
int  levelsup = 0 
) const
protectedvirtual

Returns the word id associated to a feature

Parameters
feature
id(out) word id
weight(out) word weight
nid(out) if given, id of the node "levelsup" levels up
levelsup

Definition at line 1218 of file TemplatedVocabulary.h.

template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const TDescriptor &  feature,
WordId id 
) const
protectedvirtual

Returns the word id associated to a feature

Parameters
feature
id(out) word id

Definition at line 1209 of file TemplatedVocabulary.h.

Member Data Documentation

template<class TDescriptor, class F>
int DBoW2::TemplatedVocabulary< TDescriptor, F >::m_k
protected

Branching factor.

Definition at line 408 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
int DBoW2::TemplatedVocabulary< TDescriptor, F >::m_L
protected

Depth levels.

Definition at line 411 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
std::vector<Node> DBoW2::TemplatedVocabulary< TDescriptor, F >::m_nodes
protected

Tree nodes.

Definition at line 423 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
ScoringType DBoW2::TemplatedVocabulary< TDescriptor, F >::m_scoring
protected

Scoring method.

Definition at line 417 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
GeneralScoring* DBoW2::TemplatedVocabulary< TDescriptor, F >::m_scoring_object
protected

Object for computing scores.

Definition at line 420 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
WeightingType DBoW2::TemplatedVocabulary< TDescriptor, F >::m_weighting
protected

Weighting method.

Definition at line 414 of file TemplatedVocabulary.h.

template<class TDescriptor, class F>
std::vector<Node*> DBoW2::TemplatedVocabulary< TDescriptor, F >::m_words
protected

Words of the vocabulary (tree leaves) this condition holds: m_words[wid]->word_id == wid

Definition at line 427 of file TemplatedVocabulary.h.


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


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47