comparison c/Parameters.cpp @ 137:445e773c9be3

created the parameter structure to parse parameters (bug remaining)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 19 Aug 2011 01:35:45 -0400
parents
children 6f10a227486c
comparison
equal deleted inserted replaced
136:0f790de9437e 137:445e773c9be3
1 #include "Parameters.hpp"
2
3 #include <boost/program_options.hpp>
4
5 #include <iostream>
6 #include <fstream>
7
8 namespace po = boost::program_options;
9 using namespace std;
10
11 KLTFeatureTrackingParameters::KLTFeatureTrackingParameters(const int argc, char* argv[]) {
12 std::string configurationFilename;
13 po::options_description onlyCmdLine("Command line only");
14 po::options_description cmdLineAndFile("Command line and configuration file");
15
16 // configuration filename
17 onlyCmdLine.add_options()
18 ("config-file", po::value<string>(&configurationFilename)->default_value("tracking.cfg"), "configuration file")
19 ;
20
21 po::positional_options_description p;
22 p.add("config-file", 1);
23
24 // common to cnnfiguration and command line
25 cmdLineAndFile.add_options()
26 ("help,h", "displays this help message")
27 ("video-filename", po::value<string>(&videoFilename), "filename of the video to process")
28 ("database-filename", po::value<string>(&databaseFilename), "filename of the database where results are saved")
29 ("homography-filename", po::value<string>(&homographyFilename), "filename of the homography matrix")
30 ("mask-filename", po::value<string>(&maskFilename), "filename of the mask image (where features are detected)")
31 ("load-features", po::value<bool>(&loadFeatures), "load features from database")
32 ("display", po::value<bool>(&display), "display trajectories on the video")
33 ("video-fps", po::value<float>(&videoFPS), "original video frame rate")
34 ("frame1", po::value<int>(&frame1), "first frame to process")
35 ("nframes", po::value<int>(&nFrames), "number of frame to process")
36 // feature tracking
37 ("max-nfeatures", po::value<int>(&maxNFeatures), "maximum number of features added at each frame")
38 ("feature-quality", po::value<float>(&featureQuality), "quality level of the good features to track")
39 ("min-feature-distanceklt", po::value<float>(&minFeatureDistanceKLT), "minimum distance between features")
40 ("window-size", po::value<int>(&windowSize), "size of the search window at each pyramid level")
41 ("use-harris-detector", po::value<bool>(&useHarrisDetector), "use of Harris corner detector")
42 ("k", po::value<float>(&k), "k parameter to detect good features to track (OpenCV)")
43 ("pyramid-level", po::value<int>(&pyramidLevel), "maximal pyramid level in the feature tracking algorithm")
44 ("ndisplacements", po::value<unsigned int>(&nDisplacements), "number of displacement to test minimum feature motion")
45 ("min-feature-displacement", po::value<float>(&minFeatureDisplacement), "minimum displacement to keep features")
46 ("acceleration-bound", po::value<float>(&accelerationBound), "maximum feature acceleration")
47 ("deviation-bound", po::value<float>(&deviationBound), "maximum feature deviation")
48 ("nframes-smoothing", po::value<int>(&nFramesSmoothing), "number of frames to smooth positions (half window)")
49 ("max-number-iterations", po::value<int>(&maxNumberTrackingIterations), "maximum number of iterations to stop feature tracking")
50 ("min-tracking-error", po::value<float>(&minTrackingError), "minimum error to reach to stop feature tracking")
51 ("min-feature-time", po::value<unsigned int>(&minFeatureTime), "minimum length of a feature (number of frames) to consider a feature for grouping")
52 ("mm-connection-distance", po::value<float>(&mmConnectionDistance), "connection distance in feature grouping")
53 ("mm-segmentation-distance", po::value<float>(&mmSegmentationDistance), "segmentation distance in feature grouping")
54 ("max-distance", po::value<float>(&maxDistance), "maximum distance between features for grouping")
55 ("min-velocity-cosine", po::value<float>(&minVelocityCosine), "minimum cosine of the angle between the velocity vectors for grouping")
56 ("min-nfeatures-group", po::value<int>(&minNFeaturesPerGroup), "minimum average number of features per frame to create a vehicle hypothesis")
57 ;
58 // ("max-uturn-cosine", po::value<float>(&maxUTurnCosine), "maximum cosine value to detect U-turn")
59 // ("nframes-avoid-uturn", po::value<int>(&nFramesAvoidUTurn), "number of frames over which a feature should not make a U-turn")
60
61
62 po::options_description cmdLine;
63 cmdLine.add(onlyCmdLine).add(cmdLineAndFile);
64 try {
65 po::variables_map vm;
66 store(po::command_line_parser(argc, argv).
67 options(cmdLine).positional(p).allow_unregistered().run(), vm);
68 notify(vm);
69
70 if (vm.count("help")) {
71 cout << cmdLine << endl;
72 // cout << "Positional options:";
73 // for (unsigned int i=0; i<p.max_total_count(); i++)
74 // cout << " " << p.name_for_position(i);
75 // cout << endl;
76 exit(0);
77 }
78 cout << "Using configuration file " << configurationFilename << endl;
79
80 ifstream configurationFile(configurationFilename.c_str());
81 store(po::parse_config_file(configurationFile, cmdLineAndFile), vm);
82 notify(vm);
83
84 parameterDescription = getParameterDescription(cmdLine, vm);
85 } catch(exception& e) {
86 cout << e.what() << endl;
87 }
88 }
89
90 string KLTFeatureTrackingParameters::getParameterDescription(po::options_description& options, const po::variables_map& vm, const string& separator /* = " " */) const {
91 stringstream stream;
92 vector<boost::shared_ptr<po::option_description> > optionsVec = options.options();
93 for (unsigned int i=0; i<optionsVec.size(); ++i) {
94 boost::any value = vm[optionsVec[i]->long_name()].value();
95 if (value.type() == typeid(bool))
96 stream << boost::any_cast<bool>(value) << separator;
97 else if (value.type() == typeid(int))
98 stream << boost::any_cast<int>(value) << separator;
99 else if (value.type() == typeid(unsigned int))
100 stream << boost::any_cast<unsigned int>(value) << separator;
101 else if (value.type() == typeid(float))
102 stream << boost::any_cast<float>(value) << separator;
103 else if (value.type() == typeid(string))
104 stream << boost::any_cast<string>(value) << separator;
105 else
106 cerr << "the type of the option variable " << i << " is not int, float or string." << endl;
107 }
108
109 return stream.str();
110 }