vocabtree  0.0.1
compute_sift_simple.cxx
Go to the documentation of this file.
1 #include "tests_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 int main(int argc, char *argv[]) {
21  LINFO << "HJ";
22 #if ENABLE_MULTITHREADING && ENABLE_MPI
23  MPI::Init(argc, argv);
24  int rank = MPI::COMM_WORLD.Get_rank();
25  if(rank == 0) {
26 #endif
28  LINFO << simple_dataset;
29 #if ENABLE_MULTITHREADING && ENABLE_OPENMP
30 #pragma omp parallel for schedule(dynamic)
31 #endif
32  for (int64_t i = 0; i < simple_dataset.num_images(); i++) {
33 
34  std::shared_ptr<SimpleDataset::SimpleImage> image = std::static_pointer_cast<SimpleDataset::SimpleImage>(simple_dataset.image(i));
35  if (image == nullptr) continue;
36 
37  const std::string &keypoints_location = simple_dataset.location(image->feature_path("keypoints"));
38  const std::string &descriptors_location = simple_dataset.location(image->feature_path("descriptors"));
39  // if (filesystem::file_exists(keypoints_location) && filesystem::file_exists(descriptors_location)) continue;
40 
41  const std::string &image_location = simple_dataset.location(image->location());
42 
43  if (!filesystem::file_exists(image_location)) continue;
44 
45  cv::Mat im = cv::imread(image_location, cv::IMREAD_GRAYSCALE);
46 
47  cv::Mat keypoints, descriptors;
48  if (!vision::compute_sparse_sift_feature(im, nullptr, keypoints, descriptors)) continue;
49 
50  filesystem::create_file_directory(keypoints_location);
51  filesystem::create_file_directory(descriptors_location);
52 
53  filesystem::write_cvmat(keypoints_location, keypoints);
54  filesystem::write_cvmat(descriptors_location, descriptors);
55  }
56 #if ENABLE_MULTITHREADING && ENABLE_MPI
57  }
58  MPI::Finalize();
59 #endif
60  return 0;
61 }