Apollo  v5.5.0
Open source self driving car software
omt_obstacle_tracker.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
27 #include "modules/perception/camera/lib/obstacle/tracker/omt/omt.pb.h"
29 
30 namespace apollo {
31 namespace perception {
32 namespace camera {
33 struct Hypothesis {
34  int target;
35  int object;
36  float score;
37 
39  this->target = -1;
40  this->object = -1;
41  this->score = -1;
42  }
43 
44  Hypothesis(int tar, int obj, float score) {
45  this->target = tar;
46  this->object = obj;
47  this->score = score;
48  }
49 
50  bool operator<(const Hypothesis &b) const { return score < b.score; }
51 
52  bool operator>(const Hypothesis &b) const { return score > b.score; }
53 };
54 
56  public:
57  // OMTObstacleTracker() : similar_(nullptr), track_id_(0),
58  // frame_num_(0), gpu_id_(0),
59  // width_(0.0f), height_(0.0f),
60  // BaseObstacleTracker() {
61  // }
63 
64  ~OMTObstacleTracker() override = default;
65 
66  bool Init(const ObstacleTrackerInitOptions &options) override;
67  // @brief: predict candidate obstales in the new image.
68  // @param [in]: options
69  // @param [in/out]: frame
70  // candidate obstacle 2D boxes should be filled, required.
71  bool Predict(const ObstacleTrackerOptions &options,
72  CameraFrame *frame) override;
73 
74  // @brief: associate obstales by 2D information.
75  // @param [in]: options
76  // @param [in/out]: frame
77  // associated obstacles with tracking id should be filled, required,
78  // smoothed 2D&3D information can be filled, optional.
79  bool Associate2D(const ObstacleTrackerOptions &options,
80  CameraFrame *frame) override;
81 
82  // @brief: associate obstales by 3D information.
83  // @param [in]: options
84  // @param [in/out]: frame
85  // associated obstacles with tracking id should be filled, required,
86  // smoothed 3D information can be filled, optional.
87  bool Associate3D(const ObstacleTrackerOptions &options,
88  CameraFrame *frame) override;
89 
90  // @brief: track detected obstacles.
91  // @param [in]: options
92  // @param [in/out]: frame
93  // associated obstacles with tracking id should be filled, required,
94  // motion information of obstacles should be filled, required.
95  bool Track(const ObstacleTrackerOptions &options,
96  CameraFrame *frame) override;
97 
98  std::string Name() const override;
99 
100  private:
101  float ScoreAppearance(const Target &target, TrackObjectPtr object);
102 
103  float ScoreMotion(const Target &target, TrackObjectPtr object);
104  float ScoreShape(const Target &target, TrackObjectPtr object);
105  float ScoreOverlap(const Target &target, TrackObjectPtr track_obj);
106  void ClearTargets();
107  bool CombineDuplicateTargets();
108  void GenerateHypothesis(const TrackObjectPtrs &objects);
109  int CreateNewTarget(const TrackObjectPtrs &objects);
110 
111  private:
112  omt::OmtParam omt_param_;
113  FrameList frame_list_;
114  SimilarMap similar_map_;
115  std::shared_ptr<BaseSimilar> similar_ = nullptr;
116  std::vector<Target> targets_;
117  std::vector<bool> used_;
118  ObstacleReference reference_;
119  std::vector<std::vector<float> > kTypeAssociatedCost_;
120  int track_id_ = 0;
121  int frame_num_ = 0;
122  int gpu_id_ = 0;
123  float width_ = 0.0f;
124  float height_ = 0.0f;
125 
126  protected:
127  ObjectTemplateManager *object_template_manager_ = nullptr;
128 };
129 
130 } // namespace camera
131 } // namespace perception
132 } // namespace apollo
Definition: camera_frame.h:33
Definition: obstacle_reference.h:39
float score
Definition: omt_obstacle_tracker.h:36
Definition: base_obstacle_tracker.h:33
Definition: blob.h:72
OMTObstacleTracker()
Definition: omt_obstacle_tracker.h:62
int target
Definition: omt_obstacle_tracker.h:34
Hypothesis(int tar, int obj, float score)
Definition: omt_obstacle_tracker.h:44
bool operator>(const Hypothesis &b) const
Definition: omt_obstacle_tracker.h:52
std::shared_ptr< TrackObject > TrackObjectPtr
Definition: track_object.h:33
std::vector< TrackObjectPtr > TrackObjectPtrs
Definition: track_object.h:34
int object
Definition: omt_obstacle_tracker.h:35
Definition: object_template_manager.h:49
Definition: omt_obstacle_tracker.h:33
Definition: frame_list.h:62
bool operator<(const Hypothesis &b) const
Definition: omt_obstacle_tracker.h:50
Definition: target.h:33
Hypothesis()
Definition: omt_obstacle_tracker.h:38
Definition: omt_obstacle_tracker.h:55
Definition: frame_list.h:103
Definition: base_obstacle_tracker.h:35
Definition: base_obstacle_tracker.h:28