LocalizationResult.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * @file LocalizationResult.h
  3. * @brief classification result, what else?
  4. * @author Erik Rodner
  5. * @date 02/13/2008
  6. */
  7. #ifndef LocalizationResultINCLUDE
  8. #define LocalizationResultINCLUDE
  9. #include "core/image/ImageT.h"
  10. #include "core/vector/VectorT.h"
  11. #include "core/vector/MatrixT.h"
  12. #include <string>
  13. #include <vector>
  14. #include <assert.h>
  15. #include "ClassificationResult.h"
  16. #include "ClassNames.h"
  17. #include "core/basics/Persistent.h"
  18. #include <core/image/Region.h>
  19. #include <core/image/RectT.h>
  20. namespace OBJREC {
  21. class SingleLocalizationResult
  22. {
  23. private:
  24. /** used for depth ordering */
  25. int controlPoints;
  26. int xi, yi, xa, ya;
  27. bool hasRegionInformation_bool;
  28. NICE::Region reg;
  29. public:
  30. ClassificationResult *r;
  31. SingleLocalizationResult ( ClassificationResult *r, const NICE::Region & reg, int controlPoints = 0 );
  32. /**
  33. * @brief constructor
  34. * @param xi (left)
  35. * @param yi (top)
  36. * @param xa (width)
  37. * @param ya (height)
  38. */
  39. SingleLocalizationResult ( ClassificationResult *r, int xi, int yi, int xa, int ya );
  40. ~SingleLocalizationResult ();
  41. /**
  42. * @brief get the bounding box
  43. * @param xi (left)
  44. * @param yi (top)
  45. * @param xa (width)
  46. * @param ya (height)
  47. */
  48. void getBoundingBox ( int & xi, int & yi, int & xa, int & ya ) const;
  49. void getBoundingBox ( NICE::RectT<int> & rectangle ) const;
  50. void getCentroid ( double & x, double & y ) const;
  51. bool hasRegionInformation () const { return hasRegionInformation_bool; };
  52. int getControlPoints () const { return controlPoints; };
  53. const NICE::Region & getRegion () const { assert (hasRegionInformation_bool); return reg; };
  54. void addPoint ( int x, int y ) { assert(hasRegionInformation_bool); reg.add(x,y); };
  55. double getBBOverlapMeasure ( const SingleLocalizationResult & slr ) const;
  56. double getBBOverlapMeasureMin ( const SingleLocalizationResult & slr ) const;
  57. };
  58. class LocalizationResult : public std::vector<SingleLocalizationResult *>, public NICE::Persistent
  59. {
  60. private:
  61. const ClassNames *cn;
  62. NICE::Image *labeledImage;
  63. public:
  64. typedef std::vector<SingleLocalizationResult *>::iterator iterator;
  65. typedef std::vector<SingleLocalizationResult *>::const_iterator const_iterator;
  66. bool hasLabeledImage;
  67. int xsize;
  68. int ysize;
  69. enum {
  70. FILEFORMAT_PASCAL2006_RESULT = 0,
  71. FILEFORMAT_PASCAL2006_GROUNDTRUTH,
  72. FILEFORMAT_POLYGON
  73. };
  74. LocalizationResult ( int xsize = -1, int ysize = -1 );
  75. LocalizationResult ( const ClassNames *cn, int xsize = -1, int ysize = -1);
  76. LocalizationResult ( const ClassNames *cn, const NICE::Image & img, int classno );
  77. LocalizationResult ( const ClassNames *cn, const NICE::ColorImage & img );
  78. ~LocalizationResult ();
  79. void sortEmpricalDepth();
  80. void sortDescendingConfidence();
  81. void getLabeledImageCache ( NICE::Image & mark ) const;
  82. void calcLabeledImage ( NICE::Image & mark, int backgroundClassNo ) const;
  83. void setMap ( const NICE::Image & labeledImage );
  84. void displayBoxes ( NICE::ColorImage & img,
  85. const ClassNames *cn = NULL,
  86. bool display_confidence = true,
  87. bool invert = false,
  88. int width = 1) const;
  89. /**
  90. * @brief Loads image label information from the file format supported by the ImageLabeler tool.
  91. *
  92. * This function ignores the label description (xml section < legend > ) and assumes, that the label names were loaded in advance
  93. * and are present in the ClassNames reference member variable LocalizationResult::cn.
  94. *
  95. * Note: Uses class ImageInfo for loading the xml information and inserts them into this LocalizationResult class.
  96. * A future TODO would be to directly include the ImageInfo loading code here (or as part of LocalizationResult) to substitute redundancy
  97. * between the classes ImageInfo and LocalizationResult (meaning both use BoundingBoxes etc).
  98. *
  99. * Currently only rectangular bounding box information are transferred from the loaded ImageInfo instance to this class.
  100. * So, trying to use for instance Polygon data created with the ImageLabeler will fail (empty LocalizationResult).
  101. *
  102. * @param sFilename file name of the image label file (usually *.dat, xml formatted)
  103. * @see OBJREC::ImageInfo
  104. * @author Johannes Rühle
  105. * @date 2012-05-11
  106. */
  107. void loadImageInfo(std::string sFilename);
  108. void restore (std::istream & is, int format = 0);
  109. void store (std::ostream & os, int format = 0) const;
  110. void clear ();
  111. int getMaxClassno () { assert(cn != NULL); return cn->getMaxClassno(); };
  112. };
  113. } // namespace
  114. #endif