Apollo  6.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 
28 #include "modules/perception/camera/lib/obstacle/tracker/omt/proto/omt.pb.h"
30 
31 namespace apollo {
32 namespace perception {
33 namespace camera {
34 struct alignas(16) Hypothesis {
35  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36  int target;
37  int object;
38  float score;
39 
41  this->target = -1;
42  this->object = -1;
43  this->score = -1;
44  }
45 
46  Hypothesis(int tar, int obj, float score) {
47  this->target = tar;
48  this->object = obj;
49  this->score = score;
50  }
51 
52  bool operator<(const Hypothesis &b) const { return score < b.score; }
53 
54  bool operator>(const Hypothesis &b) const { return score > b.score; }
55 };
56 
58  public:
59  // OMTObstacleTracker() : similar_(nullptr), track_id_(0),
60  // frame_num_(0), gpu_id_(0),
61  // width_(0.0f), height_(0.0f),
62  // BaseObstacleTracker() {
63  // }
64  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
66 
67  ~OMTObstacleTracker() override = default;
68 
69  bool Init(const ObstacleTrackerInitOptions &options) override;
70  // @brief: predict candidate obstales in the new image.
71  // @param [in]: options
72  // @param [in/out]: frame
73  // candidate obstacle 2D boxes should be filled, required.
74  bool Predict(const ObstacleTrackerOptions &options,
75  CameraFrame *frame) override;
76 
77  // @brief: associate obstales by 2D information.
78  // @param [in]: options
79  // @param [in/out]: frame
80  // associated obstacles with tracking id should be filled, required,
81  // smoothed 2D&3D information can be filled, optional.
82  bool Associate2D(const ObstacleTrackerOptions &options,
83  CameraFrame *frame) override;
84 
85  // @brief: associate obstales by 3D information.
86  // @param [in]: options
87  // @param [in/out]: frame
88  // associated obstacles with tracking id should be filled, required,
89  // smoothed 3D information can be filled, optional.
90  bool Associate3D(const ObstacleTrackerOptions &options,
91  CameraFrame *frame) override;
92 
93  // @brief: track detected obstacles.
94  // @param [in]: options
95  // @param [in/out]: frame
96  // associated obstacles with tracking id should be filled, required,
97  // motion information of obstacles should be filled, required.
98  bool Track(const ObstacleTrackerOptions &options,
99  CameraFrame *frame) override;
100 
101  std::string Name() const override;
102 
103  private:
104  float ScoreAppearance(const Target &target, TrackObjectPtr object);
105 
106  float ScoreMotion(const Target &target, TrackObjectPtr object);
107  float ScoreShape(const Target &target, TrackObjectPtr object);
108  float ScoreOverlap(const Target &target, TrackObjectPtr track_obj);
109  void ClearTargets();
110  bool CombineDuplicateTargets();
111  void GenerateHypothesis(const TrackObjectPtrs &objects);
112  int CreateNewTarget(const TrackObjectPtrs &objects);
113 
114  private:
115  omt::OmtParam omt_param_;
116  FrameList frame_list_;
117  SimilarMap similar_map_;
118  std::shared_ptr<BaseSimilar> similar_ = nullptr;
120  std::vector<bool> used_;
121  ObstacleReference reference_;
122  std::vector<std::vector<float>> kTypeAssociatedCost_;
123  int track_id_ = 0;
124  int frame_num_ = 0;
125  int gpu_id_ = 0;
126  float width_ = 0.0f;
127  float height_ = 0.0f;
128 
129  protected:
130  ObjectTemplateManager *object_template_manager_ = nullptr;
131 };
132 
133 } // namespace camera
134 } // namespace perception
135 } // namespace apollo
std::vector< EigenType, Eigen::aligned_allocator< EigenType > > EigenVector
Definition: eigen_defs.h:32
Definition: camera_frame.h:33
Definition: obstacle_reference.h:41
float score
Definition: omt_obstacle_tracker.h:38
Definition: base_obstacle_tracker.h:33
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Hypothesis(int tar, int obj, float score)
Definition: omt_obstacle_tracker.h:46
bool operator>(const Hypothesis &b) const
Definition: omt_obstacle_tracker.h:54
std::shared_ptr< TrackObject > TrackObjectPtr
Definition: track_object.h:34
std::vector< TrackObjectPtr > TrackObjectPtrs
Definition: track_object.h:35
int object
Definition: omt_obstacle_tracker.h:37
Definition: object_template_manager.h:49
Definition: omt_obstacle_tracker.h:34
Definition: frame_list.h:63
bool operator<(const Hypothesis &b) const
Definition: omt_obstacle_tracker.h:52
Definition: target.h:34
EIGEN_MAKE_ALIGNED_OPERATOR_NEW OMTObstacleTracker()
Definition: omt_obstacle_tracker.h:65
EIGEN_MAKE_ALIGNED_OPERATOR_NEW int target
Definition: omt_obstacle_tracker.h:36
bool Init(const char *binary_name)
Hypothesis()
Definition: omt_obstacle_tracker.h:40
Definition: omt_obstacle_tracker.h:57
Definition: frame_list.h:105
Definition: base_obstacle_tracker.h:35
Definition: base_obstacle_tracker.h:28