/** * @file LFSegmentation.cpp * @brief Local Features are connected components of a arbitrary segmentation * @author Erik Rodner * @date 01/21/2008 */ #ifdef NICE_USELIB_ICE #include #include #include #include #include "vislearning/features/localfeatures/LFSegmentation.h" #include "vislearning/segmentation/SegLocal.h" #include using namespace OBJREC; using namespace std; using namespace NICE; LFSegmentation::LFSegmentation( const Config *conf ) { segmentation = new SegLocal ( conf ); } LFSegmentation::~LFSegmentation() { delete segmentation; } int LFSegmentation::getDescSize () const { return 1; } int LFSegmentation::extractFeatures ( const NICE::Image & img, VVector & features, VVector & positions ) const { std::vector contours; segmentation->getContours ( img, contours ); ice::Matrix xcoordinate (0,4); for ( vector::const_iterator i = contours.begin(); i != contours.end(); i++ ) { int xi, yi, xa, ya; i->GetRect(xi, yi, xa, ya); if ( (ya == yi) || (xa == xi) ) continue; xcoordinate.Append ( ice::Vector(xi,yi,xa-xi,ya-yi) ); } xcoordinate.Sort(); for ( int i = 0 ; i < xcoordinate.rows() ; i++ ) { NICE::Vector f (1); f.set(0.0); features.push_back(f); positions.push_back( NICE::makeEVector(xcoordinate[i]) ); } return positions.size(); } void LFSegmentation::visualizeFeatures ( NICE::Image & mark, const VVector & positions, size_t color ) const { for ( size_t i = 0 ; i < positions.size() ; i++ ) { const NICE::Vector & pos = positions[i]; int x = (int)pos[0]; int y = (int)pos[1]; int w = (int)pos[2]; int h = (int)pos[3]; RectangleT rect ( Coord(x, y), Coord(x+w, y+w) ); mark.draw ( rect, (unsigned char)color ); } } #endif