vocabtree  0.0.1
bench_compute_features.cxx
Go to the documentation of this file.
1 #include "bench_config.hpp"
2 
3 #include <config.hpp>
4 
5 #include <utils/filesystem.hpp>
6 #include <utils/dataset.hpp>
7 #include <utils/vision.hpp>
8 #include <utils/logger.hpp>
9 #include <iostream>
10 
11 #if ENABLE_MULTITHREADING && ENABLE_OPENMP
12 #include <omp.h>
13 #endif
14 #if ENABLE_MULTITHREADING && ENABLE_MPI
15 #include <mpi.h>
16 #endif
17 
18 _INITIALIZE_EASYLOGGINGPP
19 
20 
21 void compute_features(const SimpleDataset &dataset) {
22  LINFO << dataset;
23 #if ENABLE_MULTITHREADING && ENABLE_OPENMP
24 #pragma omp parallel for schedule(dynamic)
25 #endif
26  for (int64_t i = 0; i < (int64_t)dataset.num_images(); i++) {
27  std::shared_ptr<SimpleDataset::SimpleImage> image = std::static_pointer_cast<SimpleDataset::SimpleImage>(dataset.image(i));
28  if (image == nullptr) continue;
29 
30  const std::string &keypoints_location = dataset.location(image->feature_path("keypoints"));
31  const std::string &descriptors_location = dataset.location(image->feature_path("descriptors"));
32 
33  const std::string &image_location = dataset.location(image->location());
34  if (!filesystem::file_exists(image_location)) continue;
35 
36 
37  cv::Mat im = cv::imread(image_location, cv::IMREAD_GRAYSCALE);
38 
39  cv::Mat keypoints, descriptors;
40  if (!vision::compute_sparse_sift_feature(im, nullptr, keypoints, descriptors)) continue;
41 
42  filesystem::create_file_directory(keypoints_location);
43  filesystem::create_file_directory(descriptors_location);
44 
45  filesystem::write_cvmat(keypoints_location, keypoints);
46  filesystem::write_cvmat(descriptors_location, descriptors);
47  }
48 }
49 
50 int main(int argc, char *argv[]) {
51 #if ENABLE_MULTITHREADING && ENABLE_MPI
52  MPI::Init(argc, argv);
53 #endif
54  // {
55  // SimpleDataset oxford_dataset(s_oxford_data_dir, s_oxford_database_location);
56  // compute_features(oxford_dataset);
57  // }
58 
59  {
61  compute_features(oxford100k_dataset);
62  }
63 #if ENABLE_MULTITHREADING && ENABLE_MPI
64  MPI::Finalize();
65 #endif
66  return 0;
67 }