LFonHSG.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 ){ cerr << "[err] sample-scaling (" << sampleScaling << ") musst be larger the 0!" << endl; return; }
  55. debug && clog << "[log] LocalFeatureHSG::getPositionsOnHSG calculate ";
  56. bool oddRow = true;
  57. NICE::Vector pos( 4 );
  58. /** we have to calculate the koo. for every different scale **/
  59. for( vector <float>::const_iterator it = scalesV.begin(); it != scalesV.end(); ++it )
  60. {
  61. oddRow = true;
  62. for( unsigned int j = sampleScaling; j <= ( imageHeight - sampleScaling ); j += sampleScaling )
  63. {
  64. for( unsigned int i = ( oddRow ? sampleScaling + sampleScaling / 2 : sampleScaling ); i <= ( imageWidth - sampleScaling ); i += sampleScaling )
  65. {
  66. pos[ 0] = i; pos[ 1] = j; pos[ 2] = *it; pos[ 3] = 0;
  67. positions.push_back( pos );
  68. }
  69. oddRow = !oddRow;
  70. }
  71. }
  72. }
  73. int LFonHSG::extractFeatures ( const NICE::ColorImage & cimg, VVector & features, VVector & positions ) const
  74. {
  75. /** To get the keypoint descriptor, we need the positions of the keypoints. **/
  76. getPositionsOnHSG( cimg.width(), cimg.height(), positions );
  77. /** calulate the descriptor-values **/
  78. return lf->getDescriptors( cimg, positions, features );
  79. }
  80. int LFonHSG::extractFeatures ( const NICE::Image & img, VVector & features, VVector & positions ) const
  81. {
  82. /** To get the keypoint descriptor, we need the positions of the keypoints. **/
  83. getPositionsOnHSG( img.width(), img.height(), positions );
  84. /** calculate the descriptor-values **/
  85. return lf->getDescriptors( img, positions, features );
  86. }
  87. void LFonHSG::visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const
  88. {
  89. // TODO: Implementierung des gewaehlten Descriptortyps aufrufen.
  90. }
  91. float LFonHSG::strToFloat( const string str ) const
  92. {
  93. float temp;
  94. stringstream ss;
  95. ss << str;
  96. ss >> temp;
  97. return temp;
  98. }