licornea_tools
export_feature_depths.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 #include <vector>
4 #include <cmath>
5 #include <algorithm>
6 #include <fstream>
7 #include <set>
8 #include <map>
10 #include "../lib/args.h"
11 #include "../lib/misc.h"
12 #include "../lib/dataset.h"
13 #include "../lib/json.h"
14 
15 using namespace tlz;
16 
17 
18 int main(int argc, const char* argv[]) {
19  get_args(argc, argv, "dataset_parameters.json in_cors.json depths.txt [y_index]");
20  dataset datas = dataset_arg();
22  std::string depths_filename = out_filename_arg();
23  int y = int_opt_arg(-1);
24 
25  if(datas.is_2d() && y == -1) throw std::runtime_error("must specify y index for 2D dataset");
26 
27  std::cout << "saving feature depths" << std::endl;
28  std::ofstream depths_stream(depths_filename);
29 
30  depths_stream << 'X';
31  for(int x : datas.x_indices()) depths_stream << ' ' << x;
32  depths_stream << '\n';
33 
34  for(const auto& kv : cors.features) {
35  const std::string& feature_name = kv.first;
36  const image_correspondence_feature& feature = kv.second;
37  depths_stream << feature_name;
38  for(int x : datas.x_indices()) {
39  depths_stream << ' ';
40  view_index view_idx(x, y);
41 
42  auto pt_it = feature.points.find(view_idx);
43  if(pt_it == feature.points.end()) continue;
44  const feature_point& pt = pt_it->second;
45 
46  real depth = pt.depth;
47  if(depth != 0.0) depths_stream << depth;
48  }
49  depths_stream << '\n';
50  }
51  std::cout << "done" << std::endl;
52 }
53 
long int_opt_arg(long def)
Definition: args.h:50
bool is_2d() const
Definition: dataset.cc:137
Set of features, each on set of views.
std::map< std::string, image_correspondence_feature > features
dataset dataset_arg()
Definition: dataset.cc:297
std::vector< int > x_indices() const
Definition: dataset.cc:190
double real
Definition: common.h:16
int main(int argc, const char *argv[])
image_correspondences image_correspondences_arg()
std::string out_filename_arg()
Definition: args.cc:104
Feature on set of views. Optionally one view is "reference".
std::map< view_index, feature_point > points
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49