NStage.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Created by wrede on 25.04.16.
  3. //
  4. #ifndef GBMOT_NSTAGE_H
  5. #define GBMOT_NSTAGE_H
  6. #include "../core/DetectionSequence.h"
  7. #include "../core/Tracklet.h"
  8. #include "../graph/Definitions.h"
  9. namespace algo
  10. {
  11. /**
  12. * Implementation of the two-staged graph-based multi-object tracker.
  13. * Extended to allow N stages.
  14. */
  15. class NStage
  16. {
  17. private:
  18. /**
  19. * Maximum edge length to link object
  20. */
  21. std::vector<size_t> max_frame_skips_;
  22. /**
  23. * Edge value to link to source and sink
  24. */
  25. std::vector<double> penalty_values_;
  26. /**
  27. * Maximum dijkstra iterations / number of tracklets to create
  28. */
  29. std::vector<size_t> max_tracklet_counts_;
  30. /**
  31. * Number of iterations
  32. */
  33. size_t iterations_;
  34. /**
  35. * The maximum edge weights the edge can have to be created in the initial graph building
  36. */
  37. double edge_weight_threshold_;
  38. /**
  39. * The constraints to ensure when creating edges
  40. */
  41. std::vector<std::unordered_map<std::string, double>> constraints_;
  42. /**
  43. * Creates a graph with vertices for every detected object
  44. *
  45. * @param graph The graph to write into
  46. * @param detections The objects to use for the graph
  47. * @param constraints The constraints to assure when creating edges
  48. */
  49. void CreateObjectGraph(DirectedGraph & graph, core::DetectionSequence & detections);
  50. /**
  51. * Reduces the object graph into linked tracklets.
  52. *
  53. * @param obj_graph The object graph to reduce
  54. * @param tlt_graph The graph to write the tracklets in
  55. * @param frame_count The frame count of the object graph
  56. * @param iteration The current iteration
  57. */
  58. void CreateTrackletGraph(DirectedGraph & obj_graph, DirectedGraph & tlt_graph,
  59. size_t frame_count, size_t iteration);
  60. /**
  61. * Extracts the finished tracks from the given tracklet graph.
  62. *
  63. * @param tlt_graph The tracklet graph to extract from
  64. * @param depth The depth to flatten the tracklets to
  65. * @param tracks The vector to write the extracted tracks in
  66. */
  67. void ExtractTracks(DirectedGraph& tlt_graph, size_t depth,
  68. std::vector<core::TrackletPtr> & tracks);
  69. public:
  70. /**
  71. * Initializes the algorithm wih the given values.
  72. * The number of stages is determined by the size of the given
  73. * vectors.
  74. *
  75. * @param max_frame_skip The maximum edge length to link objects
  76. * @param penalty_value The edge value to link to source and sink
  77. * @param max_tracklet_count The maximum number of tracklets to create
  78. * @param edge_weight_threshold The maximum weight an edge can have in the initial graph,
  79. * edges with higher weights are discarded
  80. * @param constraints The constraints to ensure when creating edges
  81. */
  82. NStage(std::vector<size_t> max_frame_skip,
  83. std::vector<double> penalty_value,
  84. std::vector<size_t> max_tracklet_count,
  85. double edge_weight_threshold,
  86. std::vector<std::unordered_map<std::string, double>> constraints);
  87. /**
  88. * Runs the algorithm on the specified sequence and stores the found tracks into the
  89. * specified tracks vector.
  90. *
  91. * @param sequence The detection values to use
  92. * @param tracks A vector to store the found tracks in
  93. */
  94. void Run(core::DetectionSequence & sequence,
  95. std::vector<core::TrackletPtr> & tracks);
  96. };
  97. }
  98. #endif //GBMOT_NSTAGE_H