ObjectData.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Created by wrede on 19.04.16.
  3. //
  4. #ifndef GBMOT_OBJECTDATA_H
  5. #define GBMOT_OBJECTDATA_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. /**
  16. * Base class for all detected objects.
  17. * Stores the corresponding frame index.
  18. */
  19. class ObjectData
  20. {
  21. private:
  22. static const std::string CONSTRAINT_FRAME_DIFFERENCE;
  23. static const std::string CONSTRAINT_SCORE_DIFFERENCE;
  24. /**
  25. * If this node is considered virtual
  26. */
  27. const bool is_virtual_;
  28. /**
  29. * The frame the object was detected in
  30. */
  31. std::size_t frame_index_;
  32. /**
  33. * The detection score.
  34. * Defines the quality of this detection.
  35. */
  36. double detection_score_;
  37. /**
  38. * Used in the << operator
  39. * @param os The stream to write to
  40. */
  41. virtual void Print(std::ostream& os) const;
  42. public:
  43. /**
  44. * Creates a new empty virtual ObjectData
  45. */
  46. ObjectData();
  47. /**
  48. * Creates a new ObjectData with the given frame index
  49. * @param frame_index the index in which the object was detected
  50. */
  51. ObjectData(std::size_t frame_index);
  52. /**
  53. * Gets the frame index
  54. * @return The frame index
  55. */
  56. std::size_t GetFrameIndex() const;
  57. /**
  58. * Sets the frame index
  59. * @param index The new frame index
  60. */
  61. void SetFrameIndex(size_t index);
  62. /**
  63. * Sets the detection score
  64. * @param score The detection score
  65. */
  66. void SetDetectionScore(double score);
  67. /**
  68. * Gets the detection score
  69. * @return The detection score
  70. */
  71. double GetDetectionScore() const;
  72. /**
  73. * Is this node considered a virtual node
  74. * @return True, if this node is virtual
  75. */
  76. bool IsVirtual() const;
  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. * Checks if the difference between this object and the specified object is within the
  85. * constraints specified. The difference is calculated for each constraint separately.
  86. *
  87. * @param obj The object to get the difference to
  88. * @param constraints The constraints to assure
  89. */
  90. virtual bool IsWithinConstraints(ObjectDataPtr obj,
  91. std::unordered_map<std::string, double> & constraints)
  92. const;
  93. /**
  94. * Linearly interpolates between this and the given object.
  95. * Creates a new object to fit between the two objects.
  96. * @param obj A pointer to the target object
  97. * @param fraction Describes where the interpolation should
  98. * be done. A fraction of zero is a clone of this object,
  99. * a fraction of one is a clone of the target object.
  100. * @return The interpolated object
  101. */
  102. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const;
  103. /**
  104. * Visualizes the object in the given image with the given color.
  105. * This method does nothing, it needs to be overwritten to visualize
  106. * something.
  107. * @param image The image to write into
  108. * @param color The color to use
  109. * @param alpha The alpha channel value in the range [0.0, 1.0]
  110. */
  111. virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const;
  112. /**
  113. * Overrides the << operator for custom output.
  114. * Calls the print method.
  115. * @param os The stream to write to
  116. * @param obj The object to write into the stream
  117. * @return The stream written to
  118. */
  119. friend std::ostream& operator<<(std::ostream& os, const ObjectData& obj);
  120. /**
  121. * Returns a string representing the values of this object data.
  122. *
  123. * @param delimiter The delimiter used to separate values
  124. * @return The string containing the values
  125. */
  126. virtual std::string ToString(char delimiter) const;
  127. };
  128. }
  129. #endif //GBMOT_OBJECTDATA_H