Tracklet.h 3.9 KB

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