Tracklet.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. /**
  73. * Visualizes the tracklet by visualizing the path object in the given
  74. * frame and the number of path objects in the given range before and
  75. * after the given frame.
  76. * @param image The image to write into
  77. * @param color The color to use
  78. * @param frame The frame index to visualize the path objects from
  79. * @param predecessor_count The number of path objects to visualize
  80. * before the given frame
  81. * @param successor_count The number of path objects to visualize after
  82. * the given frame
  83. * @param True, if only points should be drawn
  84. */
  85. void Visualize(cv::Mat& image, cv::Scalar& color, size_t frame,
  86. size_t predecessor_count, size_t successor_count, bool points) const;
  87. /**
  88. * Flattens the current tracklet one level.
  89. * That means, that if this tracklet contains other tracklets as path
  90. * objects, their path objects are all extracted and used as the new
  91. * path objects of this tracklet. The old tracklet path objects are
  92. * removed.
  93. */
  94. void Flatten();
  95. /**
  96. * Copies all detections from the specified tracklet to this tracklet
  97. *
  98. * @param other The tracklet to copy the detections from
  99. */
  100. void Combine(TrackletPtr other);
  101. /**
  102. * Gets the detected object at the given frame index or a nullptr if there is not detection.
  103. *
  104. * @param frame_index The index of the frame to take the detection from
  105. * @return A pointer to the detection in the given frame
  106. */
  107. ObjectDataPtr GetFrameObject(size_t frame_index);
  108. virtual double CompareTo(ObjectDataPtr obj) const override;
  109. virtual bool IsWithinConstraints(ObjectDataPtr obj,
  110. std::unordered_map<std::string, double> & constraints) const override;
  111. virtual ObjectDataPtr Interpolate(ObjectDataPtr obj, double fraction) const override;
  112. virtual void Visualize(cv::Mat& image, cv::Scalar& color, double alpha) const override;
  113. };
  114. }
  115. #endif //GBMOT_TRACKLET_H