Tracklet.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // Created by wrede on 25.04.16.
  3. //
  4. #ifndef GBMOT_TRACKLET_H
  5. #define GBMOT_TRACKLET_H
  6. #include <cstdlib>
  7. #include <vector>
  8. #include "ObjectData.h"
  9. namespace core
  10. {
  11. /**
  12. * A class for storing multiple object data objects.
  13. * The object data objects are handled as a path.
  14. * All objects are stored sorted ascending by their frame index.
  15. */
  16. class Tracklet : public ObjectData
  17. {
  18. private:
  19. /**
  20. * The path objects.
  21. * Sorted ascending by their frame index.
  22. */
  23. std::vector<ObjectDataPtr> path_objects_;
  24. /**
  25. * The highest frame index of all objects in the path.
  26. */
  27. size_t last_frame_index_;
  28. virtual void Print(std::ostream& os) const;
  29. public:
  30. /**
  31. * Creates a empty tracklet to store path object in.
  32. * This is NOT a virtual object.
  33. */
  34. Tracklet();
  35. /**
  36. * Adds the path object sorted into the tracklet.
  37. * @param obj The path object to add
  38. * @param overwrite If true and an object in the same frame as the given
  39. * object already exists, the old one will be replaced
  40. * by the new one
  41. */
  42. void AddPathObject(ObjectDataPtr obj, bool overwrite = false);
  43. /**
  44. * Gets the lowest frame index of all path objects.
  45. * @return The lowest frame index
  46. */
  47. size_t GetFirstFrameIndex() const;
  48. /**
  49. * Gets the highest frame index of all path objects.
  50. * @return The highest frame index
  51. */
  52. size_t GetLastFrameIndex() const;
  53. /**
  54. * Gets the path object at the given index.
  55. * The index is NOT the frame index
  56. * @return A pointer to the path object
  57. */
  58. ObjectDataPtr GetPathObject(size_t i);
  59. /**
  60. * Gets the count of all path objects.
  61. * @return The path object count
  62. */
  63. size_t GetPathObjectCount() const;
  64. /**
  65. * Interpolates between the current path objects until every missing
  66. * frame has an object. Only frames between the first frame index and
  67. * the last frame index are interpolated.
  68. */
  69. void InterpolateMissingFrames();
  70. virtual double CompareTo(ObjectDataPtr obj) const override;
  71. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj,
  72. double fraction) const override;
  73. virtual void Visualize(cv::Mat& image, cv::Scalar& color) const override;
  74. /**
  75. * Visualizes the tracklet by visualizing the path object in the given
  76. * frame and the number of path objects in the given range before and
  77. * after the given frame.
  78. * @param image The image to write into
  79. * @param color The color to use
  80. * @param frame The frame index to visualize the path objects from
  81. * @param predecessor_count The number of path objects to visualize
  82. * before the given frame
  83. * @param successor_count The number of path objects to visualize after
  84. * the given frame
  85. */
  86. void Visualize(cv::Mat& image, cv::Scalar& color, size_t frame,
  87. size_t predecessor_count, size_t successor_count) const;
  88. /**
  89. * Flattens the current tracklet one level.
  90. * That means, that if this tracklet contains other tracklets as path
  91. * objects, their path objects are all extracted and used as the new
  92. * path objects of this tracklet. The old tracklet path objects are
  93. * removed.
  94. */
  95. void Flatten();
  96. };
  97. }
  98. #endif //GBMOT_TRACKLET_H