DBoW2::TemplatedVocabulary< TDescriptor, F > Class Template Reference

Generic Vocabulary. More...

#include <TemplatedVocabulary.h>

List of all members.

Classes

struct  Node
 Tree node. More...

Public Member Functions

 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 ~TemplatedVocabulary ()
TemplatedVocabulary
< TDescriptor, F > & 
operator= (const TemplatedVocabulary< TDescriptor, F > &voc)
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 unsigned int size () const
virtual bool empty () const
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
double score (const BowVector &a, const BowVector &b) const
virtual NodeId getParentNode (WordId wid, int levelsup) const
void getWordsFromNode (NodeId nid, std::vector< WordId > &words) const
int getBranchingFactor () const
int getDepthLevels () const
float getEffectiveLevels () const
virtual TDescriptor getWord (WordId wid) const
virtual WordValue getWordWeight (WordId wid) const
WeightingType getWeightingType () const
ScoringType getScoringType () const
void setWeightingType (WeightingType type)
void setScoringType (ScoringType type)
void save (const std::string &filename) const
void load (const std::string &filename)
virtual void save (cv::FileStorage &fs, const std::string &name="vocabulary") const
virtual void load (const cv::FileStorage &fs, const std::string &name="vocabulary")
virtual int stopWords (double minWeight)

Protected Types

typedef const TDescriptor * pDescriptor
 Pointer to descriptor.

Protected Member Functions

void createScoringObject ()
void getFeatures (const vector< vector< TDescriptor > > &training_features, vector< pDescriptor > &features) const
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
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 createWords ()
void setNodeWeights (const vector< vector< TDescriptor > > &features)

Protected Attributes

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

Detailed Description

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

Generic Vocabulary.

Parameters:
TDescriptor class of descriptor
F class of descriptor functions

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 
) [inline]

Initiates an empty vocabulary

Parameters:
k branching factor
L depth levels
weighting weighting type
scoring scoring type
template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( const std::string &  filename  )  [inline]

Creates the vocabulary by loading a file

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

Creates the vocabulary by loading a file

Parameters:
filename 
template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary ( const TemplatedVocabulary< TDescriptor, F > &  voc  )  [inline]

Copy constructor

Parameters:
voc 
template<class TDescriptor , class F >
DBoW2::TemplatedVocabulary< TDescriptor, F >::~TemplatedVocabulary (  )  [inline, virtual]

Destructor


Member Function Documentation

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 
) [inline, 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

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

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

Parameters:
training_features 
k branching factor
L depth levels
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create ( const std::vector< std::vector< TDescriptor > > &  training_features  )  [inline, virtual]

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

Parameters:
training_features 
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::createScoringObject (  )  [inline, protected]

Creates an instance of the scoring object accoring to m_scoring

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

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

template<class TDescriptor , class F >
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::empty (  )  const [inline, virtual]

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

Returns:
true iff the vocabulary is empty
template<class TDescriptor, class F>
int DBoW2::TemplatedVocabulary< TDescriptor, F >::getBranchingFactor (  )  const [inline]

Returns the branching factor of the tree (k)

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

Returns the depth levels of the tree (L)

Returns:
L
template<class TDescriptor , class F >
float DBoW2::TemplatedVocabulary< TDescriptor, F >::getEffectiveLevels (  )  const [inline]

Returns the real depth levels of the tree on average

Returns:
average of depth levels of leaves
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getFeatures ( const vector< vector< TDescriptor > > &  training_features,
vector< pDescriptor > &  features 
) const [inline, protected]

Returns a set of pointers to descriptores

Parameters:
training_features all the features
features (out) pointers to the training features
template<class TDescriptor , class F >
NodeId DBoW2::TemplatedVocabulary< TDescriptor, F >::getParentNode ( WordId  wid,
int  levelsup 
) const [inline, virtual]

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

Parameters:
wid word id
levelsup 0..L
Returns:
node id. if levelsup is 0, returns the node id associated to the word id
template<class TDescriptor, class F>
ScoringType DBoW2::TemplatedVocabulary< TDescriptor, F >::getScoringType (  )  const [inline]

Returns the scoring method

Returns:
scoring method
template<class TDescriptor, class F>
WeightingType DBoW2::TemplatedVocabulary< TDescriptor, F >::getWeightingType (  )  const [inline]

Returns the weighting method

Returns:
weighting method
template<class TDescriptor , class F >
TDescriptor DBoW2::TemplatedVocabulary< TDescriptor, F >::getWord ( WordId  wid  )  const [inline, virtual]

Returns the descriptor of a word

Parameters:
wid word id
Returns:
descriptor
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordsFromNode ( NodeId  nid,
std::vector< WordId > &  words 
) const [inline]

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:
nid starting node id
words ids of words
template<class TDescriptor , class F >
WordValue DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordWeight ( WordId  wid  )  const [inline, virtual]

Returns the weight of a word

Parameters:
wid word id
Returns:
weight
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::HKmeansStep ( NodeId  parent_id,
const vector< pDescriptor > &  descriptors,
int  current_level 
) [inline, 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_id id of parent node
descriptors descriptors to run the kmeans on
current_level current level in the tree
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClusters ( const vector< pDescriptor > &  descriptors,
vector< TDescriptor > &  clusters 
) const [inline, protected, virtual]

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.
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClustersKMpp ( const vector< pDescriptor > &  descriptors,
vector< TDescriptor > &  clusters 
) const [inline, protected]

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

Parameters:
descriptors 
clusters resulting clusters
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load ( const cv::FileStorage &  fs,
const std::string &  name = "vocabulary" 
) [inline, virtual]

Loads the vocabulary from a file storage node

Parameters:
fn first node
subname name of the child node of fn where the tree is stored. If not given, the fn node is used instead
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load ( const std::string &  filename  )  [inline]

Loads the vocabulary from a file

Parameters:
filename 
template<class TDescriptor , class F >
TemplatedVocabulary< TDescriptor, F > & DBoW2::TemplatedVocabulary< TDescriptor, F >::operator= ( const TemplatedVocabulary< TDescriptor, F > &  voc  )  [inline]

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
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save ( cv::FileStorage &  fs,
const std::string &  name = "vocabulary" 
) const [inline, virtual]

Saves the vocabulary to a file storage structure

Parameters:
fn node in file storage
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save ( const std::string &  filename  )  const [inline]

Saves the vocabulary into a file

Parameters:
filename 
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:
a vector
b vector
Returns:
score between vectors
Note:
the vectors must be already sorted and normalized if necessary
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setNodeWeights ( const vector< vector< TDescriptor > > &  features  )  [inline, 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 
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setScoringType ( ScoringType  type  )  [inline]

Changes the scoring method

Parameters:
type new scoring type
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setWeightingType ( WeightingType  type  )  [inline]

Changes the weighting method

Parameters:
type new weighting type
template<class TDescriptor , class F >
unsigned int DBoW2::TemplatedVocabulary< TDescriptor, F >::size (  )  const [inline, virtual]

Returns the number of words in the vocabulary

Returns:
number of words
template<class TDescriptor , class F >
int DBoW2::TemplatedVocabulary< TDescriptor, F >::stopWords ( double  minWeight  )  [inline, 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
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const TDescriptor &  feature,
WordId id 
) const [inline, protected, virtual]

Returns the word id associated to a feature

Parameters:
feature 
id (out) word id
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 [inline, protected, virtual]

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 
template<class TDescriptor , class F >
WordId DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const TDescriptor &  feature  )  const [inline, virtual]

Transforms a single feature into a word (without weight)

Parameters:
feature 
Returns:
word id
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const std::vector< TDescriptor > &  features,
BowVector v,
FeatureVector fv,
int  levelsup 
) const [inline, 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
levelsup levels to go up the vocabulary tree to get the node index
template<class TDescriptor , class F >
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform ( const std::vector< TDescriptor > &  features,
BowVector v 
) const [inline, virtual]

Transforms a set of descriptores into a bow vector

Parameters:
features 
v (out) bow vector of weighted words

Member Data Documentation

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Generated on Thu Feb 7 19:47:43 2013 by  doxygen 1.6.3