LFonHSG.cpp 3.7 KB

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