samplewriteconfigfile.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "opencv2/core.hpp"
  2. #include <iostream>
  3. #include <string>
  4. using namespace cv;
  5. using namespace std;
  6. int main(int argc,const char ** argv){
  7. CommandLineParser parser(argc, argv,
  8. "{ help h usage ? | | give the following arguments in following format }"
  9. "{ filename f |. | (required) path to file which you want to create as config file [example - /data/config.xml] }"
  10. "{ cascade_depth cd | 10 | (required) This stores the depth of cascade of regressors used for training.}"
  11. "{ tree_depth td | 4 | (required) This stores the depth of trees created as weak learners during gradient boosting.}"
  12. "{ num_trees_per_cascade_level| 500 | (required) This stores number of trees required per cascade level.}"
  13. "{ learning_rate | 0.1 | (required) This stores the learning rate for gradient boosting.}"
  14. "{ oversampling_amount | 20 | (required) This stores the oversampling amount for the samples.}"
  15. "{ num_test_coordinates | 400 | (required) This stores number of test coordinates required for making the split.}"
  16. "{ lambda | 0.1 | (required) This stores the value used for calculating the probabilty.}"
  17. "{ num_test_splits | 20 | (required) This stores the number of test splits to be generated before making the best split.}"
  18. );
  19. // Read in the input arguments
  20. if (parser.has("help")){
  21. parser.printMessage();
  22. cerr << "TIP: Use absolute paths to avoid any problems with the software!" << endl;
  23. return 0;
  24. }
  25. //These variables have been initialised as defined in the research paper "One millisecond face alignment" CVPR 2014
  26. int cascade_depth = 15;
  27. int tree_depth = 4;
  28. int num_trees_per_cascade_level = 500;
  29. float learning_rate = float(0.1);
  30. int oversampling_amount = 20;
  31. int num_test_coordinates = 400;
  32. float lambda = float(0.1);
  33. int num_test_splits = 20;
  34. cascade_depth = parser.get<int>("cascade_depth");
  35. tree_depth = parser.get<int>("tree_depth");
  36. num_trees_per_cascade_level = parser.get<int>("num_trees_per_cascade_level");
  37. learning_rate = parser.get<float>("learning_rate");
  38. oversampling_amount = parser.get<int>("oversampling_amount");
  39. num_test_coordinates = parser.get<int>("num_test_coordinates");
  40. lambda = parser.get<float>("lambda");
  41. num_test_splits = parser.get<int>("num_test_splits");
  42. string filename(parser.get<string>("filename"));
  43. FileStorage fs(filename, FileStorage::WRITE);
  44. if (!fs.isOpened())
  45. {
  46. cerr << "Failed to open " << filename << endl;
  47. parser.printMessage();
  48. return -1;
  49. }
  50. fs << "cascade_depth" << cascade_depth;
  51. fs << "tree_depth"<< tree_depth;
  52. fs << "num_trees_per_cascade_level" << num_trees_per_cascade_level;
  53. fs << "learning_rate" << learning_rate;
  54. fs << "oversampling_amount" << oversampling_amount;
  55. fs << "num_test_coordinates" << num_test_coordinates;
  56. fs << "lambda" << lambda ;
  57. fs << "num_test_splits"<< num_test_splits;
  58. fs.release();
  59. cout << "Write Done." << endl;
  60. return 0;
  61. }