ImageInfo.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * @file ImageInfo.h
  3. * @brief localization info + image filename + ?
  4. * @author Erik Rodner
  5. * @date 04/16/2008
  6. */
  7. #ifndef IMAGEINFOINCLUDE
  8. #define IMAGEINFOINCLUDE
  9. #include "core/image/ImageT.h"
  10. #include "core/vector/VectorT.h"
  11. #include "core/vector/MatrixT.h"
  12. #include "vislearning/cbaselib/Polygon.h"
  13. #include "vislearning/cbaselib/BoundingBox.h"
  14. #include "vislearning/cbaselib/CategoryInfo.h"
  15. #include "LocalizationResult.h"
  16. #include <assert.h>
  17. #ifdef NICE_USELIB_QT4_XML
  18. class QString;
  19. class QDomElement;
  20. #endif //NICE_USELIB_QT4_XML
  21. namespace OBJREC
  22. {
  23. /**
  24. * @brief Class for loading label information created by the ImageLabeler tool.
  25. *
  26. * The label file format is xml consisting of several sections about the label desription,
  27. * occuring objects (such as bounding boxes and polygons) and their label ids, and reference to the
  28. * original image file.
  29. *
  30. * Note: Be aware of the code redundancy of the xml loading presented here and the separate code in the ImageLabeler tool.
  31. * Both try to interprete/load the label xml but with different code, so changes at one code place do not affect the other one.
  32. *
  33. * Second note/todo: in future this class should complete be integrated into LocalizationResult, which also includes bounding box label info
  34. * and is more integrated into NICE feature extraction and classification mechanism.
  35. * Currently, to convert a loaded label file into a LocalizationResult, use function LocalizationResult::loadImageInfo() (currently only bounding box information).
  36. *
  37. * localization info + image filename + ?
  38. */
  39. class ImageInfo
  40. {
  41. protected:
  42. std::string imagefn;
  43. LocalizationResult *lr;
  44. bool localization_info;
  45. #ifdef NICE_USELIB_QT4_XML
  46. Polygon polyFromData ( QString *aPolyData );
  47. BoundingBox BBoxFromData ( QString *aBBoxData, int &id );
  48. void loadLegendFromElement ( QDomElement *anElement );
  49. bool loadCategoryInfo ( QDomElement *anElement );
  50. NICE::ImageT< unsigned int > imageTFromData (
  51. const int &aWidth,
  52. const int &aHeight,
  53. QString *aPureData
  54. );
  55. #endif //NICE_USELIB_QT4_XML
  56. public:
  57. /**
  58. * @brief simple constructor
  59. * @param _imagefn image file name
  60. * @param _lr Localization result containing label information
  61. */
  62. ImageInfo ( const std::string & _imagefn, LocalizationResult *_lr ) :
  63. imagefn ( _imagefn ), lr ( _lr ), localization_info ( true ) {};
  64. ImageInfo() {};
  65. ImageInfo ( const std::string & _imagefn ) :
  66. imagefn ( _imagefn ), lr ( NULL ), localization_info ( false ) {};
  67. /** simple destructor */
  68. virtual ~ImageInfo();
  69. const std::string & img () const
  70. {
  71. return imagefn;
  72. };
  73. /**
  74. * @brief Returns available localization information.
  75. *
  76. * Note: This class doesn't create a new LocalizationResult instance - it only returns the reference to a previously assigned instance (see constructor).
  77. * To convert a loaded label file into a LocalizationResult, use function LocalizationResult::loadImageInfo() (currently only bounding box information).
  78. * @see LocalizationResult::loadImageInfo()
  79. */
  80. const LocalizationResult *localization () const
  81. {
  82. assert ( localization_info );
  83. return lr;
  84. };
  85. bool hasLocalizationInfo () const
  86. {
  87. return localization_info;
  88. };
  89. bool loadImageInfo ( const std::string &aFilename );
  90. const std::list< CategoryInfo > * labels() const;
  91. const std::list< BoundingBox > * bboxes() const;
  92. const std::list< Polygon > * polys() const;
  93. NICE::ImageT< unsigned int > labeledImage() const;
  94. std::string tags() const;
  95. std::string imagePath() const;
  96. std::string imageDescription() const;
  97. std::string segmentedImagePath() const;
  98. private:
  99. std::list< CategoryInfo > labels_;
  100. std::list< BoundingBox > bboxes_;
  101. std::list< Polygon > polys_;
  102. NICE::ImageT< unsigned int > labeled_image_;
  103. //std::list< std::string > tags_;
  104. std::string tags_;
  105. std::string image_path_;
  106. std::string image_description_;
  107. std::string segmented_image_path_;
  108. };
  109. } // namespace
  110. #endif