vocabtree  0.0.1
bench_search.cxx File Reference
#include "bench_config.hpp"
#include <fstream>
#include <config.hpp>
#include <utils/filesystem.hpp>
#include <utils/numerics.hpp>
#include <utils/dataset.hpp>
#include <utils/misc.hpp>
#include <utils/vision.hpp>
#include <utils/logger.hpp>
#include <utils/image.hpp>
#include <utils/cycletimer.hpp>
#include <search/bag_of_words/bag_of_words.hpp>
#include <search/inverted_index/inverted_index.hpp>
#include <vis/matches_page.hpp>
Include dependency graph for bench_search.cxx:

Go to the source code of this file.

Functions

_INITIALIZE_EASYLOGGINGPP void bench_oxford ()
 
int main (int argc, char *argv[])
 

Function Documentation

_INITIALIZE_EASYLOGGINGPP void bench_oxford ( )

Definition at line 27 of file bench_search.cxx.

References MatchesPage::add_match(), CycleTimer::currentSeconds(), ENABLE_MPI, ENABLE_MULTITHREADING, ENABLE_OPENMP, vision::geo_verify_f(), misc::get_machine_name(), vision::is_good_match(), filesystem::load_cvmat(), Dataset::location(), SimpleDataset::SimpleImage::location(), s_oxford_data_dir, s_oxford_database_location, s_oxford_num_clusters, and MatchesPage::write().

Referenced by main().

27  {
28 
29  MatchesPage html_output;
30 
31  const uint32_t num_clusters = s_oxford_num_clusters;
32 
34  LINFO << oxford_dataset;
35 
36  std::stringstream index_output_file;
37  index_output_file << oxford_dataset.location() << "/index/" << num_clusters << ".index";
38  InvertedIndex ii(index_output_file.str());
39 
40  double total_time = 0.0;
41  uint32_t num_validate = 16;
42  uint32_t total_iterations = 256;
43  for(uint32_t i=0; i<total_iterations; i++) {
44  double start_time = CycleTimer::currentSeconds();
45  std::shared_ptr<InvertedIndex::MatchResults> matches =
46  std::static_pointer_cast<InvertedIndex::MatchResults>(ii.search(oxford_dataset, nullptr, oxford_dataset.image(i)));
47  if(matches == nullptr) {
48  LERROR << "Error while running search.";
49  continue;
50  }
51  double end_time = CycleTimer::currentSeconds();
52  total_time += (end_time - start_time);
53 
54 
55  // validate matches
56  cv::Mat keypoints_0, descriptors_0;
57  std::shared_ptr<SimpleDataset::SimpleImage> query_image = std::static_pointer_cast<SimpleDataset::SimpleImage>(oxford_dataset.image(i));
58  const std::string &query_keypoints_location = oxford_dataset.location(query_image->feature_path("keypoints"));
59  const std::string &query_descriptors_location = oxford_dataset.location(query_image->feature_path("descriptors"));
60  filesystem::load_cvmat(query_keypoints_location, keypoints_0);
61  filesystem::load_cvmat(query_descriptors_location, descriptors_0);
62  std::vector<int> validated(num_validate, 0);
63 #if ENABLE_MULTITHREADING && ENABLE_OPENMP
64  #pragma omp parallel for schedule(dynamic)
65 #endif
66  for(int32_t j=0; j<(int32_t)num_validate; j++) {
67  cv::Mat keypoints_1, descriptors_1;
68  std::shared_ptr<SimpleDataset::SimpleImage> match_image = std::static_pointer_cast<SimpleDataset::SimpleImage>(oxford_dataset.image(matches->matches[j]));
69  const std::string &match_keypoints_location = oxford_dataset.location(match_image->feature_path("keypoints"));
70  const std::string &match_descriptors_location = oxford_dataset.location(match_image->feature_path("descriptors"));
71  filesystem::load_cvmat(match_keypoints_location, keypoints_1);
72  filesystem::load_cvmat(match_descriptors_location, descriptors_1);
73 
74  cv::detail::MatchesInfo match_info;
75  vision::geo_verify_f(descriptors_0, keypoints_0, descriptors_1, keypoints_1, match_info);
76 
77  validated[j] = vision::is_good_match(match_info) ? 1 : -1;
78  }
79 
80  html_output.add_match(i, matches->matches, oxford_dataset, std::make_shared< std::vector<int> >(validated));
81  html_output.write(oxford_dataset.location() + "/results/matches/");
82  }
83 
84 
85 
86 
87  // Write out the timings
88  std::stringstream timings_file_name;
89  timings_file_name << oxford_dataset.location() + "/results/times.index." << ii.num_clusters() << ".csv";
90  std::ofstream ofs(timings_file_name.str(), std::ios::app);
91  if((size_t)ofs.tellp() == 0) {
92  std::stringstream header;
93  header << "machine\ttime(s)\titerations\tmultithreading\topenmp\tmpi\t" << std::endl;
94  ofs.write(header.str().c_str(), header.str().size());
95  }
96  std::stringstream timing;
97  timing << misc::get_machine_name() << "\t" << total_time << "\t" << total_iterations << "\t" <<
99  "\t" << ENABLE_MPI << "\t" << std::endl;
100  ofs.write(timing.str().c_str(), timing.str().size());
101  ofs.close();
102 
103  // validate matches
104 
105 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 107 of file bench_search.cxx.

References bench_oxford().

107  {
108 #if ENABLE_MULTITHREADING && ENABLE_MPI
109  MPI::Init(argc, argv);
110  int rank = MPI::COMM_WORLD.Get_rank();
111  if(rank == 0) {
112 #endif
113 
114  bench_oxford();
115 
116 #if ENABLE_MULTITHREADING && ENABLE_MPI
117  }
118  MPI::Finalize();
119 #endif
120  return 0;
121 }