Optimization of Visual Odometry System  1.2.0
CS133 Course Project
bow_tools.cpp
Go to the documentation of this file.
1 
8 #include "bow_tools.hpp"
9 
10 
11 using namespace cv;
18 void build_dictionary(Mat & dictionary)
19 {
20  std::string file_path = "../../data/rgbd_dataset_freiburg2_desk/rgb.txt";
21  std::ifstream in(file_path);
22  std::string time_stamp, file_name;
23  if (!in.is_open())
24  {
25  std::cout << "Error opening file" << std::endl;
26  }
27  for (int i = 0; i < 3; i++ )
28  {
29  std::string tmp1, tmp2, tmp3;
30  in >> tmp1 >> tmp2 >> tmp3;
31  }
32 
33  Mat img;
34  Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
35  std::vector<KeyPoint> key_points;
36  Mat descriptor;
37 
38 
39  TermCriteria tc(CV_TERMCRIT_ITER, 100, 0.001);
40  int dictionarySize = 100;
41  int retries = 1;
42  int flags = KMEANS_PP_CENTERS;
43  BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
44 
45 
46  int count = 0;
47  while(!in.eof())
48  {
49  if (count % 200 != 0)
50  {
51  in >> time_stamp >> file_name;
52  count ++;
53  continue;
54  }
55  in >> time_stamp >> file_name;
56  std::string pre_path = "../../data/rgbd_dataset_freiburg2_desk/";
57  file_name = pre_path+file_name;
58  img = imread(file_name);
59  f2d->detect(img, key_points);
60  f2d->compute(img, key_points, descriptor);
61  bowTrainer.add(descriptor);
62  count ++;
63  }
64  in.close();
65  dictionary = bowTrainer.cluster();
66 }
bow_tools.hpp
This file contains some handy functions which will be used in bag of word algorithm.
build_dictionary
void build_dictionary(Mat &dictionary)
Definition: bow_tools.cpp:18