SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIOrbVocabulary Class Reference

#include <WAIOrbVocabulary.h>

Public Member Functions

 WAIOrbVocabulary (int layer=2)
 
 ~WAIOrbVocabulary ()
 
void loadFromFile (std::string strVocFile)
 
void create (std::vector< cv::Mat > &features, int k, int l)
 
void transform (const cv::Mat &descriptors, WAIBowVector &bow, WAIFeatVector &feat)
 
double score (WAIBowVector &bow1, WAIBowVector &bow2)
 
size_t size ()
 
void save (std::string path)
 
void setLayer (int layer)
 

Public Attributes

fbow::Vocabulary * _vocabulary = nullptr
 

Private Attributes

int _layer
 

Detailed Description

Definition at line 51 of file WAIOrbVocabulary.h.

Constructor & Destructor Documentation

◆ WAIOrbVocabulary()

WAIOrbVocabulary::WAIOrbVocabulary ( int  layer = 2)

Definition at line 14 of file WAIOrbVocabulary.cpp.

15 {
16 #if USE_FBOW
17  _vocabulary = new fbow::Vocabulary();
18 #else
19  _vocabulary = new ORB_SLAM2::ORBVocabulary();
20 #endif
21  _layer = layer;
22 }
fbow::Vocabulary * _vocabulary

◆ ~WAIOrbVocabulary()

WAIOrbVocabulary::~WAIOrbVocabulary ( )

Definition at line 24 of file WAIOrbVocabulary.cpp.

25 {
26  if (_vocabulary)
27  {
28 #if USE_FBOW
29  _vocabulary->clear();
30 #endif
31  delete _vocabulary;
32  }
33 
34  _vocabulary = nullptr;
35 }

Member Function Documentation

◆ create()

void WAIOrbVocabulary::create ( std::vector< cv::Mat > &  features,
int  k,
int  l 
)

Definition at line 120 of file WAIOrbVocabulary.cpp.

121 {
122 #if USE_FBOW
123  fbow::VocabularyCreator vc;
124  fbow::VocabularyCreator::Params p;
125  p.k = k;
126  p.L = l;
127  p.nthreads = 100;
128  p.maxIters = 11;
129  p.verbose = true;
130 
131  std::cout << "Creating a " << p.k << "^" << p.L << " vocabulary..." << std::endl;
132  _vocabulary = new fbow::Vocabulary();
133 
134  vc.create(*_vocabulary, features, "slamvoc", p);
135  std::cout << "... done!" << std::endl;
136 #else
137  const DBoW2::WeightingType weight = DBoW2::TF_IDF;
138  const DBoW2::ScoringType score = DBoW2::L1_NORM;
139 
140  std::vector<std::vector<cv::Mat>> feats;
141  feats.resize(features.size());
142 
143  cout << "Creating a " << k << "^" << l << " vocabulary..." << endl;
144  for (int i = 0; i < features.size(); i++)
145  {
146  feats[i].resize(features[i].rows);
147  for (int j = 0; j < features[i].rows; j++)
148  feats[i].push_back(features[i].row(j));
149  }
150 
151  _vocabulary = new ORB_SLAM2::ORBVocabulary(k, l, weight, score);
152  _vocabulary->create(feats);
153 
154  cout << "... done!" << endl;
155 #endif
156 }
double score(WAIBowVector &bow1, WAIBowVector &bow2)

◆ loadFromFile()

void WAIOrbVocabulary::loadFromFile ( std::string  strVocFile)

Definition at line 38 of file WAIOrbVocabulary.cpp.

39 {
40  if (!_vocabulary)
41  {
42 #if USE_FBOW
43  _vocabulary = new fbow::Vocabulary();
44 #else
45  _vocabulary = new ORB_SLAM2::ORBVocabulary();
46 #endif
47  }
48 
49 #if USE_FBOW
50  try
51  {
52  _vocabulary->readFromFile(strVocFile);
53  }
54  catch (std::exception& e)
55  {
56  std::string err = "WAIOrbVocabulary::loadFromFile: failed to load vocabulary " +
57  strVocFile + ", exception:" + e.what();
58  throw std::runtime_error(err);
59  }
60 #else
61  bool bVocLoad = _vocabulary->loadFromBinaryFile(strVocFile);
62 
63  if (!bVocLoad)
64  {
65  std::string err = "WAIOrbVocabulary::loadFromFile: failed to load vocabulary " + strVocFile;
66  Utils::log("WAI", err.c_str());
67  throw std::runtime_error(err);
68  }
69 #endif
70 }
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1103

◆ save()

void WAIOrbVocabulary::save ( std::string  path)

Definition at line 158 of file WAIOrbVocabulary.cpp.

159 {
160 #if USE_FBOW
161  _vocabulary->saveToFile(path);
162 #else
163  _vocabulary->saveToBinaryFile(path);
164 #endif
165 }

◆ score()

double WAIOrbVocabulary::score ( WAIBowVector bow1,
WAIBowVector bow2 
)

Definition at line 102 of file WAIOrbVocabulary.cpp.

103 {
104 #if USE_FBOW
105  return fbow::fBow::score(bow1.data, bow2.data);
106 #else
107  return _vocabulary->score(bow1.data, bow2.data);
108 #endif
109 }
fbow::fBow data

◆ setLayer()

void WAIOrbVocabulary::setLayer ( int  layer)
inline

Definition at line 68 of file WAIOrbVocabulary.h.

68 { _layer = layer; }

◆ size()

size_t WAIOrbVocabulary::size ( )

Definition at line 111 of file WAIOrbVocabulary.cpp.

112 {
113 #if USE_FBOW
114  return _vocabulary->size() * _vocabulary->getK();
115 #else
116  return _vocabulary->size();
117 #endif
118 }

◆ transform()

void WAIOrbVocabulary::transform ( const cv::Mat &  descriptors,
WAIBowVector bow,
WAIFeatVector feat 
)

Definition at line 86 of file WAIOrbVocabulary.cpp.

87 {
88  bow.isFill = true;
89  feat.isFill = true;
90 
91  if (descriptors.rows == 0)
92  return;
93 
94 #if USE_FBOW
95  _vocabulary->transform(descriptors, _layer, bow.data, feat.data);
96 #else
97  vector<cv::Mat> vCurrentDesc = ORB_SLAM2::Converter::toDescriptorVector(descriptors);
98  _vocabulary->transform(vCurrentDesc, bow.data, feat.data, _vocabulary->getDepthLevels() - _layer);
99 #endif
100 }
fbow::fBow2 data

Member Data Documentation

◆ _layer

int WAIOrbVocabulary::_layer
private

Definition at line 71 of file WAIOrbVocabulary.h.

◆ _vocabulary

fbow::Vocabulary* WAIOrbVocabulary::_vocabulary = nullptr

Definition at line 60 of file WAIOrbVocabulary.h.


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