tracker.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // The code is based on:
  15. // https://github.com/CnybTseng/JDE/blob/master/platforms/common/jdetracker.h
  16. // Ths copyright of CnybTseng/JDE is as follows:
  17. // MIT License
  18. #pragma once
  19. #include <map>
  20. #include <vector>
  21. #include <opencv2/core/core.hpp>
  22. #include <opencv2/highgui/highgui.hpp>
  23. #include <opencv2/imgproc/imgproc.hpp>
  24. #include "include/trajectory.h"
  25. namespace PaddleDetection {
  26. typedef std::map<int, int> Match;
  27. typedef std::map<int, int>::iterator MatchIterator;
  28. struct Track {
  29. int id;
  30. float score;
  31. cv::Vec4f ltrb;
  32. };
  33. class JDETracker {
  34. public:
  35. static JDETracker *instance(void);
  36. virtual bool update(const cv::Mat &dets,
  37. const cv::Mat &emb,
  38. std::vector<Track> *tracks);
  39. private:
  40. JDETracker(void);
  41. virtual ~JDETracker(void) {}
  42. cv::Mat motion_distance(const TrajectoryPtrPool &a, const TrajectoryPool &b);
  43. void linear_assignment(const cv::Mat &cost,
  44. float cost_limit,
  45. Match *matches,
  46. std::vector<int> *mismatch_row,
  47. std::vector<int> *mismatch_col);
  48. void remove_duplicate_trajectory(TrajectoryPool *a,
  49. TrajectoryPool *b,
  50. float iou_thresh = 0.15f);
  51. private:
  52. static JDETracker *me;
  53. int timestamp;
  54. TrajectoryPool tracked_trajectories;
  55. TrajectoryPool lost_trajectories;
  56. TrajectoryPool removed_trajectories;
  57. int max_lost_time;
  58. float lambda;
  59. float det_thresh;
  60. };
  61. } // namespace PaddleDetection