testPHOGFeatures.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <iostream>
  2. #include "core/basics/Config.h"
  3. #include "vislearning/features/gradientfeatures/PHOGFeature.h"
  4. #include <unistd.h>
  5. using namespace std;
  6. using namespace NICE;
  7. using namespace OBJREC;
  8. int main(int argc, char **argv)
  9. {
  10. Config *conf;
  11. std::string imgfilename ("/progs/square_black.jpg");
  12. if(argc < 1)
  13. {
  14. std::cerr << "No config file given, use default config and ./progs/square_black.jpg instaed" << std::endl;
  15. conf = new Config();
  16. char path_c[512];
  17. getcwd(path_c, 512);
  18. if (path_c == NULL)
  19. {
  20. std::cerr << "default image is not readable. Aborting." << std::endl;
  21. return -1 ;
  22. }
  23. std::string path(path_c);
  24. imgfilename = path + imgfilename;
  25. }
  26. else
  27. {
  28. conf = new Config( argc, argv );
  29. imgfilename = conf->gS("main", "imgfilename", "");
  30. if (imgfilename.compare("") == 0)
  31. {
  32. std::cerr << "No input image given. Aborting!" << std::endl;
  33. return -1;
  34. }
  35. }
  36. PHOGFeature PHOG(conf);
  37. PHOG.sayYourName();
  38. std::cerr << "Concatenating NONE histograms resulting in \\sum_{i=0}{level} 4^i histograms." << std::endl;
  39. PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::NONE);
  40. std::vector<std::vector<float> > resulting_feature = PHOG.createOneFeatureVector(imgfilename);
  41. for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
  42. {
  43. for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
  44. {
  45. std::cerr << *j << " ";
  46. }
  47. std::cerr << std::endl << std::endl;
  48. }
  49. std::cerr << "Concatenating histograms LEVELWISE resulting in #level histograms." << std::endl;
  50. PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::LEVELWISE);
  51. resulting_feature = PHOG.createOneFeatureVector(imgfilename);
  52. for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
  53. {
  54. for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
  55. {
  56. std::cerr << *j << " ";
  57. }
  58. std::cerr << std::endl << std::endl;
  59. }
  60. std::cerr << "Concatenating ALL histograms resulting in 1 final histogram." << std::endl;
  61. PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::ALL);
  62. resulting_feature = PHOG.createOneFeatureVector(imgfilename);
  63. for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
  64. {
  65. for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
  66. {
  67. std::cerr << *j << " ";
  68. }
  69. std::cerr << std::endl << std::endl;
  70. }
  71. return 0;
  72. }