/** * @file LFonHSG.cpp * @brief Implementation of the LocalFeatureHSG.h. See description there. * @author Eric Bach * @date 26.10.2011 */ /* LocalFeatureHSG Include */ #include "vislearning/features/localfeatures/LFonHSG.h" using namespace OBJREC; using namespace NICE; using namespace std; LFonHSG::LFonHSG ( const Config *conf, const string section ) { /** initialization **/ this->lf = NULL; /** get parameters for the grid **/ sampleScaling = conf->gI ( section, "sample_scaling", 50 ); scales = conf->gS ( section, "scales" , "1" ); // the scales are seperated by '+', like in the Van de Sande implementation char separator = '+'; /** get debuginformation **/ debug = conf->gB ( "debug", "show_log_HSG", false ); /** generate the descriptor-instanz **/ lf = GenericLocalFeatureSelection::selectLocalFeature ( conf, section ); /** parse scales string **/ debug && clog << "[log] LocalFeatureHSG::LocalFeatureHSG" << endl; debug && clog << "[log] try to parse the 'scales-string': " << scales << " -> "; #ifdef NICE_USELIB_BOOST typedef tokenizer > tokenizer; char_separator sep ( separator ); tokenizer tokens ( scales, sep ); // parse the string into tokens for ( tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter ) { debug && clog << *tok_iter << " "; scalesV.push_back ( strToFloat ( *tok_iter ) ); } #else // standard vector temp; StringTools::split ( scales, separator, temp ); for ( vector::const_iterator it = temp.begin(); it != temp.end(); ++it ) { debug && clog << *it << " "; scalesV.push_back ( strToFloat ( *it ) ); } #endif debug && clog << endl; } LFonHSG::~LFonHSG() { /** free memory of descriptors **/ } void LFonHSG::getPositionsOnHSG ( const unsigned int imageWidth, const unsigned int imageHeight, VVector& positions ) const { if ( sampleScaling < 1 ) { cerr << "[err] sample-scaling (" << sampleScaling << ") musst be larger the 0!" << endl; return; } debug && clog << "[log] LocalFeatureHSG::getPositionsOnHSG calculate "; bool oddRow = true; NICE::Vector pos ( 4 ); /** we have to calculate the koo. for every different scale **/ for ( vector ::const_iterator it = scalesV.begin(); it != scalesV.end(); ++it ) { oddRow = true; for ( unsigned int j = sampleScaling; j <= ( imageHeight - sampleScaling ); j += sampleScaling ) { for ( unsigned int i = ( oddRow ? sampleScaling + sampleScaling / 2 : sampleScaling ); i <= ( imageWidth - sampleScaling ); i += sampleScaling ) { pos[ 0] = i; pos[ 1] = j; pos[ 2] = *it; pos[ 3] = 0; positions.push_back ( pos ); } oddRow = !oddRow; } } } int LFonHSG::extractFeatures ( const NICE::ColorImage & cimg, VVector & features, VVector & positions ) const { /** To get the keypoint descriptor, we need the positions of the keypoints. **/ getPositionsOnHSG ( cimg.width(), cimg.height(), positions ); /** calulate the descriptor-values **/ return lf->getDescriptors ( cimg, positions, features ); } int LFonHSG::extractFeatures ( const NICE::Image & img, VVector & features, VVector & positions ) const { /** To get the keypoint descriptor, we need the positions of the keypoints. **/ getPositionsOnHSG ( img.width(), img.height(), positions ); /** calculate the descriptor-values **/ return lf->getDescriptors ( img, positions, features ); } void LFonHSG::visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const { // TODO: Implementierung des gewaehlten Descriptortyps aufrufen. } float LFonHSG::strToFloat ( const string str ) const { float temp; stringstream ss; ss << str; ss >> temp; return temp; }