LFSegmentation.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file LFSegmentation.cpp
  3. * @brief Local Features are connected components of a arbitrary segmentation
  4. * @author Erik Rodner
  5. * @date 01/21/2008
  6. */
  7. #ifdef NICE_USELIB_ICE
  8. #include <vislearning/nice.h>
  9. #include <image_nonvis.h>
  10. #include <core/image/RectangleT.h>
  11. #include <iostream>
  12. #include "vislearning/features/localfeatures/LFSegmentation.h"
  13. #include "vislearning/segmentation/SegLocal.h"
  14. #include <core/iceconversion/convertice.h>
  15. using namespace OBJREC;
  16. using namespace std;
  17. using namespace NICE;
  18. LFSegmentation::LFSegmentation( const Config *conf )
  19. {
  20. segmentation = new SegLocal ( conf );
  21. }
  22. LFSegmentation::~LFSegmentation()
  23. {
  24. delete segmentation;
  25. }
  26. int LFSegmentation::getDescSize () const
  27. {
  28. return 1;
  29. }
  30. int LFSegmentation::extractFeatures ( const NICE::Image & img, VVector & features,
  31. VVector & positions ) const
  32. {
  33. std::vector<ice::Contur> contours;
  34. segmentation->getContours ( img, contours );
  35. ice::Matrix xcoordinate (0,4);
  36. for ( vector<ice::Contur>::const_iterator i = contours.begin();
  37. i != contours.end();
  38. i++ )
  39. {
  40. int xi, yi, xa, ya;
  41. i->GetRect(xi, yi, xa, ya);
  42. if ( (ya == yi) || (xa == xi) ) continue;
  43. xcoordinate.Append ( ice::Vector(xi,yi,xa-xi,ya-yi) );
  44. }
  45. xcoordinate.Sort();
  46. for ( int i = 0 ; i < xcoordinate.rows() ; i++ )
  47. {
  48. NICE::Vector f (1);
  49. f.set(0.0);
  50. features.push_back(f);
  51. positions.push_back( NICE::makeEVector(xcoordinate[i]) );
  52. }
  53. return positions.size();
  54. }
  55. void LFSegmentation::visualizeFeatures ( NICE::Image & mark,
  56. const VVector & positions,
  57. size_t color ) const
  58. {
  59. for ( size_t i = 0 ; i < positions.size() ; i++ )
  60. {
  61. const NICE::Vector & pos = positions[i];
  62. int x = (int)pos[0];
  63. int y = (int)pos[1];
  64. int w = (int)pos[2];
  65. int h = (int)pos[3];
  66. RectangleT<Ipp8u> rect ( Coord(x, y), Coord(x+w, y+w) );
  67. mark.draw ( rect, (unsigned char)color );
  68. }
  69. }
  70. #endif