ImageInfo.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. virtual bool polyFromData( QString *aPolyData, Polygon &p_Poly);
  47. virtual bool BBoxFromData(QString *aBBoxData, int &id , BoundingBox &p_bbox);
  48. virtual void extractSectionLegend ( QDomElement *anElement );
  49. virtual bool extractSectionImage(QDomElement *element, const std::string &p_sImageInfoFilename );
  50. virtual bool extractSectionSegmented(QDomElement *element );
  51. virtual bool extractSectionDescription(QDomElement *element );
  52. virtual bool extractSectionTags(QDomElement *element );
  53. virtual bool extractSectionObjects(QDomElement *element );
  54. virtual bool extractObjectPolygon(QDomElement *element );
  55. virtual bool extractObjectRectangle(QDomElement *element );
  56. virtual bool extractImageSize(QDomElement *element );
  57. virtual bool extractSectionPureData(QDomElement *element );
  58. virtual bool loadCategoryInfo ( QDomElement *anElement );
  59. NICE::ImageT< unsigned int > imageTFromData (
  60. const int &aWidth,
  61. const int &aHeight,
  62. QString *aPureData
  63. );
  64. #endif //NICE_USELIB_QT4_XML
  65. public:
  66. /**
  67. * @brief simple constructor
  68. * @param _imagefn image file name
  69. * @param _lr Localization result containing label information
  70. */
  71. ImageInfo ( const std::string & _imagefn, LocalizationResult *_lr ) :
  72. imagefn ( _imagefn ), lr ( _lr ), localization_info ( true ) {};
  73. ImageInfo() {};
  74. ImageInfo ( const std::string & _imagefn ) :
  75. imagefn ( _imagefn ), lr ( NULL ), localization_info ( false ) {};
  76. /** simple destructor */
  77. virtual ~ImageInfo();
  78. const std::string & img () const
  79. {
  80. return imagefn;
  81. };
  82. /**
  83. * @brief Returns available localization information.
  84. *
  85. * Note: This class doesn't create a new LocalizationResult instance - it only returns the reference to a previously assigned instance (see constructor).
  86. * To convert a loaded label file into a LocalizationResult, use function LocalizationResult::loadImageInfo() (currently only bounding box information).
  87. * @see LocalizationResult::loadImageInfo()
  88. */
  89. const LocalizationResult *localization () const
  90. {
  91. assert ( localization_info );
  92. return lr;
  93. };
  94. bool hasLocalizationInfo () const
  95. {
  96. return localization_info;
  97. };
  98. virtual bool loadImageInfo ( const std::string &aFilename );
  99. const std::list< CategoryInfo > * labels() const;
  100. const std::list< BoundingBox > * bboxes() const;
  101. const std::list< Polygon > * polys() const;
  102. NICE::ImageT< unsigned int > labeledImage() const;
  103. std::string tags() const;
  104. std::string imagePath() const;
  105. std::string imageDescription() const;
  106. std::string segmentedImagePath() const;
  107. void setListOfPolygons( std::list< Polygon > &p_polys )
  108. {
  109. polys_ = p_polys;
  110. }
  111. protected:
  112. std::list< CategoryInfo > labels_;
  113. std::list< BoundingBox > bboxes_;
  114. std::list< Polygon > polys_;
  115. NICE::ImageT< unsigned int > labeled_image_;
  116. //std::list< std::string > tags_;
  117. std::string tags_;
  118. std::string image_path_;
  119. std::string image_description_;
  120. std::string segmented_image_path_;
  121. int m_iImageWidth;
  122. int m_iImageHeight;
  123. };
  124. } // namespace
  125. #endif