LocalizationResult.h 5.1 KB

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