ObjectData.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <opencv2/imgproc.hpp>
  11. #include <memory>
  12. namespace core
  13. {
  14. class ObjectData;
  15. typedef std::shared_ptr<ObjectData> ObjectDataPtr;
  16. //TODO RENAME ObjectDataBase / ObjectBase / DataBase / AObject / DetectionBase ...
  17. /**
  18. * Base class for all detected objects.
  19. * Stores the corresponding frame index.
  20. */
  21. class ObjectData
  22. {
  23. private:
  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. //TODO RENAME ObjectDataComparable / IComparable ...
  78. /**
  79. * Compares this object with the given object.
  80. * @param obj A pointer to the object to compare this object to
  81. * @return A double value indicating the comparison result
  82. */
  83. virtual double CompareTo(ObjectDataPtr obj) const;
  84. /**
  85. * Linearly interpolates between this and the given object.
  86. * Creates a new object to fit between the two objects.
  87. * @param obj A pointer to the target object
  88. * @param fraction Describes where the interpolation should
  89. * be done. A fraction of zero is a clone of this object,
  90. * a fraction of one is a clone of the target object.
  91. * @return The interpolated object
  92. */
  93. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const;
  94. /**
  95. * Visualizes the object in the given image with the given color.
  96. * This method does nothing, it needs to be overwritten to visualize
  97. * something.
  98. * @param image The image to write into
  99. * @param color The color to use
  100. */
  101. virtual void Visualize(cv::Mat& image, cv::Scalar& color) const;
  102. /**
  103. * Overrides the << operator for custom output.
  104. * Calls the print method.
  105. * @param os The stream to write to
  106. * @param obj The object to write into the stream
  107. * @return The stream written to
  108. */
  109. friend std::ostream& operator<<(std::ostream& os, const ObjectData& obj);
  110. };
  111. }
  112. #endif //GBMOT_NODEDATA_H