ObjectData.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Created by wrede on 19.04.16.
  3. //
  4. #ifndef GBMOT_NODEDATA_H
  5. #define GBMOT_NODEDATA_H
  6. #include <string>
  7. #include <unordered_map>
  8. #include <iostream>
  9. #include <opencv2/core/core.hpp>
  10. #include <memory>
  11. namespace core
  12. {
  13. class ObjectData;
  14. typedef std::shared_ptr<ObjectData> ObjectDataPtr;
  15. //TODO RENAME ObjectDataBase / ObjectBase / DataBase / AObject / DetectionBase ...
  16. /**
  17. * Base class for all detected objects.
  18. * Stores the corresponding frame index.
  19. */
  20. class ObjectData
  21. {
  22. private:
  23. /**
  24. * If this node is considered virtual
  25. */
  26. const bool is_virtual_;
  27. /**
  28. * The frame the object was detected in
  29. */
  30. std::size_t frame_index_;
  31. /**
  32. * The detection score.
  33. * Defines the quality of this detection.
  34. */
  35. double detection_score_;
  36. /**
  37. * Used in the << operator
  38. * @param os The stream to write to
  39. */
  40. virtual void Print(std::ostream& os) const;
  41. public:
  42. /**
  43. * Creates a new empty virtual ObjectData
  44. */
  45. ObjectData();
  46. /**
  47. * Creates a new ObjectData with the given frame index
  48. * @param frame_index the index in which the object was detected
  49. */
  50. ObjectData(std::size_t frame_index);
  51. /**
  52. * Gets the frame index
  53. * @return The frame index
  54. */
  55. std::size_t GetFrameIndex() const;
  56. /**
  57. * Sets the frame index
  58. * @param index The new frame index
  59. */
  60. void SetFrameIndex(size_t index);
  61. /**
  62. * Sets the detection score
  63. * @param score The detection score
  64. */
  65. void SetDetectionScore(double score);
  66. /**
  67. * Gets the detection score
  68. * @return The detection score
  69. */
  70. double GetDetectionScore() const;
  71. /**
  72. * Is this node considered a virtual node
  73. * @return True, if this node is virtual
  74. */
  75. bool IsVirtual() const;
  76. //TODO RENAME ObjectDataComparable / IComparable ...
  77. /**
  78. * Compares this object with the given object.
  79. * @param obj A pointer to the object to compare this object to
  80. * @return A double value indicating the comparison result
  81. */
  82. virtual double CompareTo(ObjectDataPtr obj) const;
  83. /**
  84. * Linearly interpolates between this and the given object.
  85. * Creates a new object to fit between the two objects.
  86. * @param obj A pointer to the target object
  87. * @param fraction Describes where the interpolation should
  88. * be done. A fraction of zero is a clone of this object,
  89. * a fraction of one is a clone of the target object.
  90. * @return The interpolated object
  91. */
  92. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const;
  93. /**
  94. * Visualizes the object in the given image with the given color.
  95. * This method does nothing, it needs to be overwritten to visualize
  96. * something.
  97. * @param image The image to write into
  98. * @param color The color to use
  99. */
  100. virtual void Visualize(cv::Mat& image, cv::Scalar& color) const;
  101. /**
  102. * Overrides the << operator for custom output.
  103. * Calls the print method.
  104. * @param os The stream to write to
  105. * @param obj The object to write into the stream
  106. * @return The stream written to
  107. */
  108. friend std::ostream& operator<<(std::ostream& os, const ObjectData& obj);
  109. };
  110. }
  111. #endif //GBMOT_NODEDATA_H