tracker.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2022 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. // The copyright of CnybTseng/JDE is as follows:
  17. // MIT License
  18. #pragma once
  19. #include <map>
  20. #include <vector>
  21. #include "ultra_infer/ultra_infer_model.h"
  22. #include "ultra_infer/vision/tracking/pptracking/trajectory.h"
  23. #include <opencv2/core/core.hpp>
  24. #include <opencv2/highgui/highgui.hpp>
  25. #include <opencv2/imgproc/imgproc.hpp>
  26. namespace ultra_infer {
  27. namespace vision {
  28. namespace tracking {
  29. typedef std::map<int, int> Match;
  30. typedef std::map<int, int>::iterator MatchIterator;
  31. struct Track {
  32. int id;
  33. float score;
  34. cv::Vec4f ltrb;
  35. };
  36. class ULTRAINFER_DECL JDETracker {
  37. public:
  38. JDETracker();
  39. virtual bool update(const cv::Mat &dets, const cv::Mat &emb,
  40. std::vector<Track> *tracks);
  41. virtual ~JDETracker() {}
  42. private:
  43. cv::Mat motion_distance(const TrajectoryPtrPool &a, const TrajectoryPool &b);
  44. void linear_assignment(const cv::Mat &cost, float cost_limit, Match *matches,
  45. std::vector<int> *mismatch_row,
  46. std::vector<int> *mismatch_col);
  47. void remove_duplicate_trajectory(TrajectoryPool *a, TrajectoryPool *b,
  48. float iou_thresh = 0.15f);
  49. private:
  50. int timestamp;
  51. TrajectoryPool tracked_trajectories;
  52. TrajectoryPool lost_trajectories;
  53. TrajectoryPool removed_trajectories;
  54. int max_lost_time;
  55. float lambda;
  56. float det_thresh;
  57. int count = 0;
  58. };
  59. } // namespace tracking
  60. } // namespace vision
  61. } // namespace ultra_infer