nndeploy C++ API  0.2.0
nndeploy C++ API
tracker.h
Go to the documentation of this file.
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 
15 // The code is based on:
16 // https://github.com/CnybTseng/JDE/blob/master/platforms/common/jdetracker.h
17 // Ths copyright of CnybTseng/JDE is as follows:
18 // MIT License
19 // ----------------------------------------------------------------------
20 // Modified by nndeploy on 2025-05-30
21 // ----------------------------------------------------------------------
22 #ifndef _NNDEPLOY_TRACK_TRACKER_H_
23 #define _NNDEPLOY_TRACK_TRACKER_H_
24 
25 #include <map>
26 #include <opencv2/core/core.hpp>
27 #include <opencv2/highgui/highgui.hpp>
28 #include <opencv2/imgproc/imgproc.hpp>
29 #include <vector>
30 
32 
33 namespace nndeploy {
34 namespace track {
35 
36 typedef std::map<int, int> Match;
37 typedef std::map<int, int>::iterator MatchIterator;
38 
39 struct Track {
40  int id;
41  float score;
42  cv::Vec4f ltrb;
43 };
44 
45 class JDETracker {
46  public:
48 
49  virtual bool update(const cv::Mat &dets, const cv::Mat &emb,
50  std::vector<Track> *tracks);
51  virtual ~JDETracker() {}
52 
53  private:
54  cv::Mat motion_distance(const TrajectoryPtrPool &a, const TrajectoryPool &b);
55  void linear_assignment(const cv::Mat &cost, float cost_limit, Match *matches,
56  std::vector<int> *mismatch_row,
57  std::vector<int> *mismatch_col);
58  void remove_duplicate_trajectory(TrajectoryPool *a, TrajectoryPool *b,
59  float iou_thresh = 0.15f);
60 
61  private:
62  int timestamp;
63  TrajectoryPool tracked_trajectories;
64  TrajectoryPool lost_trajectories;
65  TrajectoryPool removed_trajectories;
66  int max_lost_time;
67  float lambda;
68  float det_thresh;
69  int count = 0;
70 };
71 
72 } // namespace track
73 } // namespace nndeploy
74 
75 #endif // _NNDEPLOY_TRACK_TRACKER_H_
virtual bool update(const cv::Mat &dets, const cv::Mat &emb, std::vector< Track > *tracks)
std::map< int, int >::iterator MatchIterator
Definition: tracker.h:37
std::vector< Trajectory > TrajectoryPool
Definition: trajectory.h:37
std::map< int, int > Match
Definition: tracker.h:36
std::vector< Trajectory * > TrajectoryPtrPool
Definition: trajectory.h:40