00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include <sstream>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <string>
00025 #include <highgui.h>
00026 #include <polyora/kpttracker.h>
00027
00028 using namespace std;
00029
00030 int main(int argc, char **argv)
00031 {
00032 int max_level = 8;
00033 int min_elem = 1000;
00034 const char *descr_fn = "descriptors.dat";
00035 const char *tree_fn = 0;
00036 const char *cvt_tree_fn = 0;
00037 const char *db_fn = "visual.db";
00038 int stop=0;
00039
00040 for (int i=1; i<argc; i++) {
00041 if (i<argc-1) {
00042 if (strcmp(argv[i],"-d")==0) {
00043 descr_fn = argv[++i];
00044 continue;
00045 } else if (strcmp(argv[i],"-t")==0) {
00046 tree_fn = argv[++i];
00047 continue;
00048 } else if (strcmp(argv[i],"-C")==0) {
00049 cvt_tree_fn = argv[++i];
00050 continue;
00051 } else if (strcmp(argv[i],"-v")==0) {
00052 db_fn = argv[++i];
00053 continue;
00054 } else if (strcmp(argv[i],"-r")==0) {
00055 max_level = atoi(argv[++i]);
00056 continue;
00057 } else if (strcmp(argv[i],"-e")==0) {
00058 min_elem = atoi(argv[++i]);
00059 continue;
00060 } else if (strcmp(argv[i],"-s")==0) {
00061 stop = atoi(argv[++i]);
00062 continue;
00063 }
00064 }
00065 cout << "Available options:\n"
00066 " -d <descriptor file>\n"
00067 " -t <tree file>\n"
00068 " -v <database filename>\n"
00069 " -r <max recursion>\n"
00070 " -e <min number of elements>\n"
00071 " -s <max elements to process>\n"
00072 " -C <tree file> convert the tree file to sqlite3 database\n"
00073 ;
00074
00075 return(-1);
00076 }
00077
00078 if (cvt_tree_fn && tree_fn) {
00079 cerr << "-t and -C options are incompatible.\n";
00080 return -1;
00081 }
00082 if (cvt_tree_fn && !db_fn) {
00083 cerr << "when using -C, please specify the database target with -v <db>.\n";
00084 return -1;
00085 }
00086 kmean_tree::node_t *root;
00087 if (!cvt_tree_fn)
00088 root = kmean_tree::build_from_data(descr_fn, max_level, min_elem, stop);
00089 else
00090 root = kmean_tree::load(cvt_tree_fn);
00091
00092 if (!root) {
00093 std::cerr << descr_fn << ": unable to build tree from descriptor file\n";
00094 return -1;
00095 }
00096 std::cout << "Done. Saving result..." << std::endl;
00097 if (tree_fn)
00098 root->save(tree_fn);
00099 else {
00100 if (!root->save_to_database(db_fn)) {
00101 cerr << db_fn << ": error.\n";
00102 return -1;
00103 }
00104 }
00105
00106 return 0;
00107 }
00108
00109 template < class T >
00110 string ToString(const T &arg)
00111 {
00112 ostringstream out;
00113
00114 out << arg;
00115
00116 return(out.str());
00117 }