ObjectData.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /**
  16. * Base class for all detected objects.
  17. * Stores the corresponding frame index.
  18. */
  19. class ObjectData
  20. {
  21. private:
  22. /**
  23. * If this node is considered virtual
  24. */
  25. const bool is_virtual_;
  26. /**
  27. * The frame the object was detected in
  28. */
  29. std::size_t frame_index_;
  30. /**
  31. * The detection score.
  32. * Defines the quality of this detection.
  33. */
  34. double detection_score_;
  35. /**
  36. * Used in the << operator
  37. * @param os The stream to write to
  38. */
  39. virtual void Print(std::ostream& os) const;
  40. public:
  41. /**
  42. * Creates a new empty virtual ObjectData
  43. */
  44. ObjectData();
  45. /**
  46. * Creates a new ObjectData with the given frame index
  47. * @param frame_index the index in which the object was detected
  48. */
  49. ObjectData(std::size_t frame_index);
  50. /**
  51. * Gets the frame index
  52. * @return The frame index
  53. */
  54. std::size_t GetFrameIndex() const;
  55. /**
  56. * Sets the frame index
  57. * @param index The new frame index
  58. */
  59. void SetFrameIndex(size_t index);
  60. /**
  61. * Sets the detection score
  62. * @param score The detection score
  63. */
  64. void SetDetectionScore(double score);
  65. /**
  66. * Gets the detection score
  67. * @return The detection score
  68. */
  69. double GetDetectionScore() const;
  70. /**
  71. * Is this node considered a virtual node
  72. * @return True, if this node is virtual
  73. */
  74. bool IsVirtual() const;
  75. /**
  76. * Compares this object with the given object.
  77. * @param obj A pointer to the object to compare this object to
  78. * @return A double value indicating the comparison result
  79. */
  80. virtual double CompareTo(ObjectDataPtr obj) const;
  81. /**
  82. * Linearly interpolates between this and the given object.
  83. * Creates a new object to fit between the two objects.
  84. * @param obj A pointer to the target object
  85. * @param fraction Describes where the interpolation should
  86. * be done. A fraction of zero is a clone of this object,
  87. * a fraction of one is a clone of the target object.
  88. * @return The interpolated object
  89. */
  90. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const;
  91. /**
  92. * Visualizes the object in the given image with the given color.
  93. * This method does nothing, it needs to be overwritten to visualize
  94. * something.
  95. * @param image The image to write into
  96. * @param color The color to use
  97. */
  98. virtual void Visualize(cv::Mat& image, cv::Scalar& color) const;
  99. /**
  100. * Overrides the << operator for custom output.
  101. * Calls the print method.
  102. * @param os The stream to write to
  103. * @param obj The object to write into the stream
  104. * @return The stream written to
  105. */
  106. friend std::ostream& operator<<(std::ostream& os, const ObjectData& obj);
  107. /**
  108. * Returns a string representing the values of this object data.
  109. *
  110. * @param delimiter The delimiter used to separate values
  111. * @return The string containing the values
  112. */
  113. virtual std::string ToString(char delimiter) const;
  114. };
  115. }
  116. #endif //GBMOT_NODEDATA_H