tracker.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/opencv.hpp>
  22. #include "trajectory.h"
  23. namespace PaddleDetection {
  24. typedef std::map<int, int> Match;
  25. typedef std::map<int, int>::iterator MatchIterator;
  26. struct Track
  27. {
  28. int id;
  29. float score;
  30. cv::Vec4f ltrb;
  31. };
  32. class JDETracker
  33. {
  34. public:
  35. static JDETracker *instance(void);
  36. virtual bool update(const cv::Mat &dets, const cv::Mat &emb, std::vector<Track> &tracks);
  37. private:
  38. JDETracker(void);
  39. virtual ~JDETracker(void) {}
  40. cv::Mat motion_distance(const TrajectoryPtrPool &a, const TrajectoryPool &b);
  41. void linear_assignment(const cv::Mat &cost, float cost_limit, Match &matches,
  42. std::vector<int> &mismatch_row, std::vector<int> &mismatch_col);
  43. void remove_duplicate_trajectory(TrajectoryPool &a, TrajectoryPool &b, float iou_thresh=0.15f);
  44. private:
  45. static JDETracker *me;
  46. int timestamp;
  47. TrajectoryPool tracked_trajectories;
  48. TrajectoryPool lost_trajectories;
  49. TrajectoryPool removed_trajectories;
  50. int max_lost_time;
  51. float lambda;
  52. float det_thresh;
  53. };
  54. } // namespace PaddleDetection