LFonHSG.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @file LFonHSG.cpp
  3. * @brief Implementation of the LocalFeatureHSG.h. See description there.
  4. * @author Eric Bach
  5. * @date 26.10.2011
  6. */
  7. /* LocalFeatureHSG Include */
  8. #include "vislearning/features/localfeatures/LFonHSG.h"
  9. using namespace OBJREC;
  10. using namespace NICE;
  11. using namespace std;
  12. LFonHSG::LFonHSG ( const Config *conf, const string section )
  13. {
  14. /** initialization **/
  15. this->lf = NULL;
  16. /** get parameters for the grid **/
  17. sampleScaling = conf->gI ( section, "sample_scaling", 50 );
  18. scales = conf->gS ( section, "scales" , "1" );
  19. // the scales are seperated by '+', like in the Van de Sande implementation
  20. char separator = '+';
  21. /** get debuginformation **/
  22. debug = conf->gB ( "debug", "show_log_HSG", false );
  23. /** generate the descriptor-instanz **/
  24. lf = GenericLocalFeatureSelection::selectLocalFeature ( conf, section );
  25. /** parse scales string **/
  26. debug && clog << "[log] LocalFeatureHSG::LocalFeatureHSG" << endl;
  27. debug && clog << "[log] try to parse the 'scales-string': " << scales << " -> ";
  28. #ifdef NICE_USELIB_BOOST
  29. typedef tokenizer<boost::char_separator<char> > tokenizer;
  30. char_separator<char> sep ( separator );
  31. tokenizer tokens ( scales, sep ); // parse the string into tokens
  32. for ( tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter )
  33. {
  34. debug && clog << *tok_iter << " ";
  35. scalesV.push_back ( strToFloat ( *tok_iter ) );
  36. }
  37. #else // standard
  38. vector<string> temp;
  39. StringTools::split ( scales, separator, temp );
  40. for ( vector<string>::const_iterator it = temp.begin(); it != temp.end(); ++it )
  41. {
  42. debug && clog << *it << " ";
  43. scalesV.push_back ( strToFloat ( *it ) );
  44. }
  45. #endif
  46. debug && clog << endl;
  47. }
  48. LFonHSG::~LFonHSG()
  49. {
  50. /** free memory of descriptors **/
  51. }
  52. void LFonHSG::getPositionsOnHSG ( const unsigned int imageWidth, const unsigned int imageHeight, VVector& positions ) const
  53. {
  54. if ( sampleScaling < 1 ) {
  55. cerr << "[err] sample-scaling (" << sampleScaling << ") musst be larger the 0!" << endl;
  56. return;
  57. }
  58. debug && clog << "[log] LocalFeatureHSG::getPositionsOnHSG calculate ";
  59. bool oddRow = true;
  60. NICE::Vector pos ( 4 );
  61. /** we have to calculate the koo. for every different scale **/
  62. for ( vector <float>::const_iterator it = scalesV.begin(); it != scalesV.end(); ++it )
  63. {
  64. oddRow = true;
  65. for ( unsigned int j = sampleScaling; j <= ( imageHeight - sampleScaling ); j += sampleScaling )
  66. {
  67. for ( unsigned int i = ( oddRow ? sampleScaling + sampleScaling / 2 : sampleScaling ); i <= ( imageWidth - sampleScaling ); i += sampleScaling )
  68. {
  69. pos[ 0] = i;
  70. pos[ 1] = j;
  71. pos[ 2] = *it;
  72. pos[ 3] = 0;
  73. positions.push_back ( pos );
  74. }
  75. oddRow = !oddRow;
  76. }
  77. }
  78. }
  79. int LFonHSG::extractFeatures ( const NICE::ColorImage & cimg, VVector & features, VVector & positions ) const
  80. {
  81. /** To get the keypoint descriptor, we need the positions of the keypoints. **/
  82. getPositionsOnHSG ( cimg.width(), cimg.height(), positions );
  83. /** calulate the descriptor-values **/
  84. return lf->getDescriptors ( cimg, positions, features );
  85. }
  86. int LFonHSG::extractFeatures ( const NICE::Image & img, VVector & features, VVector & positions ) const
  87. {
  88. /** To get the keypoint descriptor, we need the positions of the keypoints. **/
  89. getPositionsOnHSG ( img.width(), img.height(), positions );
  90. /** calculate the descriptor-values **/
  91. return lf->getDescriptors ( img, positions, features );
  92. }
  93. void LFonHSG::visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const
  94. {
  95. // TODO: Implementierung des gewaehlten Descriptortyps aufrufen.
  96. }
  97. float LFonHSG::strToFloat ( const string str ) const
  98. {
  99. float temp;
  100. stringstream ss;
  101. ss << str;
  102. ss >> temp;
  103. return temp;
  104. }