make_tree_gaussian.cpp
Go to the documentation of this file.
00001 #include <vocabulary_tree/tree_builder.h>
00002 #include <boost/lexical_cast.hpp>
00003 #include <boost/foreach.hpp>
00004 #include <cstdio>
00005 #include <fstream>
00006 
00007 static const uint32_t K = 5;
00008 static const uint32_t LEVELS = 3;
00009 
00010 typedef Eigen::Vector2f Feature;
00011 typedef std::vector<Feature, Eigen::aligned_allocator<Feature> > FeatureVector;
00012 
00013 int main(int argc, char** argv)
00014 {
00015   if (argc < 3) {
00016     printf("Usage: %s samples.txt output.tree\n", argv[0]);
00017     return 0;
00018   }
00019 
00020   // Parse command-line args
00021   std::ifstream infile(argv[1]);
00022   std::string tree_file = argv[2];
00023 
00024   // Read in descriptors
00025   FeatureVector features;
00026   while (infile.good()) {
00027     Feature f;
00028     infile >> f[0] >> f[1];
00029     if (infile.good())
00030       features.push_back(f);
00031   }
00032   printf("# Training from %d descriptors\n", features.size());
00033 
00034   // Create tree
00035   vt::TreeBuilder<Feature> builder(Feature::Zero());
00036   builder.kmeans().setRestarts(5);
00037   builder.build(features, K, LEVELS);
00038   builder.tree().save(tree_file);
00039   printf("# %u centers\n", builder.tree().centers().size());
00040 
00041   // Print out centers
00042   BOOST_FOREACH(const Feature& f, builder.tree().centers()) {
00043     printf("%f %f\n", f[0], f[1]);
00044   }
00045   
00046   return 0;
00047 }


vocabulary_tree
Author(s): Patrick Mihelich
autogenerated on Thu Jan 2 2014 12:12:26