Apollo  6.0
Open source self driving car software
denseline_lane_postprocessor.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 <string>
19 #include <vector>
20 
26 #include "modules/perception/camera/lib/lane/postprocessor/denseline/proto/denseline_postprocessor.pb.h"
28 
29 namespace apollo {
30 namespace perception {
31 namespace camera {
32 
33 enum class LaneType {
34  UNKNOWN_LANE = -1,
35  EGO_LANE = 0,
38 };
39 
41  public:
43 
45 
46  bool Init(const LanePostprocessorInitOptions& options =
47  LanePostprocessorInitOptions()) override;
48 
49  // @brief: detect lane from image.
50  // @param [in]: options
51  // @param [in/out]: frame
52  // detected lanes should be filled, required,
53  // 3D information of lane can be filled, optional.
54  bool Process2D(const LanePostprocessorOptions& options,
55  CameraFrame* frame) override;
56  // convert image point to the camera coordinate
57  // & fit the line using polynomial
58  bool Process3D(const LanePostprocessorOptions& options,
59  CameraFrame* frame) override;
60 
61  std::string Name() const override;
62 
63  std::vector<std::vector<LanePointInfo>> GetLanelinePointSet();
64  std::vector<LanePointInfo> GetAllInferLinePointSet();
65 
66  void GetLaneCCs(std::vector<unsigned char>* lane_map, int* lane_map_width,
67  int* lane_map_height,
68  std::vector<ConnectedComponent>* connected_components,
69  std::vector<ConnectedComponent>* select_connected_components);
70 
71  private:
72  void ConvertImagePoint2Camera(CameraFrame* frame);
73  // @brief: locate lane line points
74  bool LocateLanelinePointSet(const CameraFrame* frame);
75  // @brief: calculate the map using network output(score map)
76  void CalLaneMap(const float* output_data, int width, int height,
77  std::vector<unsigned char>* lane_map);
78  // @brief: select lane center ccs
79  bool SelectLanecenterCCs(const std::vector<ConnectedComponent>& lane_ccs,
80  std::vector<ConnectedComponent>* select_lane_ccs);
81  // @brief: classify lane ccs position type in image
82  bool ClassifyLaneCCsPosTypeInImage(
83  const std::vector<ConnectedComponent>& select_lane_ccs,
84  std::vector<LaneType>* ccs_pos_type);
85  // @brief: compare CC's size
86  static bool CompareCCSize(const ConnectedComponent& cc1,
87  const ConnectedComponent& cc2) {
88  std::vector<base::Point2DI> cc1_pixels = cc1.GetPixels();
89  std::vector<base::Point2DI> cc2_pixels = cc2.GetPixels();
90  return cc1_pixels.size() > cc2_pixels.size();
91  }
92  // @brief: infer point set from lane center
93  void InferPointSetFromLaneCenter(
94  const std::vector<ConnectedComponent>& lane_ccs,
95  const std::vector<LaneType>& ccs_pos_type,
96  std::vector<std::vector<LanePointInfo>>* lane_map_group_point_set);
97  // @brief: infer point from one cc
98  void InferPointSetFromOneCC(
99  const ConnectedComponent& lane_cc, int left_index, int right_index,
100  std::vector<std::vector<LanePointInfo>>* lane_map_group_point_set);
101  // @brief: find the point with the maximum score
102  bool MaxScorePoint(const float* score_pointer, const float* x_pointer,
103  const int* x_count_pointer, int y_pos,
104  LanePointInfo* point_info);
105  // @brief: convert the point to the original image
106  void Convert2OriginalCoord(
107  const std::vector<std::vector<LanePointInfo>>& lane_map_group_point_set,
108  std::vector<std::vector<LanePointInfo>>* image_group_point_set);
109  // @brief: classify laneline pos type in image
110  void ClassifyLanelinePosTypeInImage(
111  const std::vector<std::vector<LanePointInfo>>& image_group_point_set,
112  std::vector<base::LaneLinePositionType>* laneline_type,
113  std::vector<bool>* line_flag);
114  // @brief: locate neighbor lane lines
115  bool LocateNeighborLaneLine(const std::vector<float>& latitude_intersection,
116  int line_index, bool left_flag,
117  int* locate_index);
118  // @brief: add image lane line
119  void AddImageLaneline(const std::vector<LanePointInfo>& image_point_set,
120  const base::LaneLineType type,
121  const base::LaneLinePositionType pos_type,
122  int line_index,
123  std::vector<base::LaneLine>* lane_marks);
124  // @brief: fit camera lane line using polynomial
125  void PolyFitCameraLaneline(CameraFrame* frame);
126 
127  private:
128  int input_image_width_ = 1920;
129  int input_image_height_ = 1080;
130  int input_offset_x_ = 0;
131  int input_offset_y_ = 440;
132  int input_crop_width_ = 1920;
133  int input_crop_height_ = 640;
134 
135  int omit_bottom_line_num_ = 3;
136  float laneline_map_score_thresh_ = 0.4f;
137  float laneline_point_score_thresh_ = 0.6f;
138  int laneline_point_min_num_thresh_ = 2;
139  float cc_valid_pixels_ratio_ = 2.0F;
140  float laneline_reject_dist_thresh_ = 50.0f;
141 
142  int lane_map_width_ = 192;
143  int lane_map_height_ = 64;
144  int lane_map_dim_ = lane_map_width_ * lane_map_height_;
145  int net_model_channel_num_ = 7;
146  float lane_max_value_ = 1e6f;
147  float lane_map_width_inverse_ = 1.0f / static_cast<float>(lane_map_width_);
148  float lane_map_height_inverse_ = 1.0f / static_cast<float>(lane_map_height_);
149 
150  lane::LanePostprocessorParam lane_postprocessor_param_;
151 
152  private:
153  std::vector<std::vector<LanePointInfo>> image_group_point_set_;
154  std::vector<std::vector<base::Point3DF>> camera_group_point_set_;
155 
156  std::vector<LanePointInfo> image_laneline_point_set_;
157  // lane map of detected pixels
158  std::vector<unsigned char> lane_map_;
159  // offset and confidence information
160  // 0: dist-left 1: dist-right 2: score
161  std::vector<float> lane_output_;
162  std::vector<ConnectedComponent> lane_ccs_;
163  std::vector<ConnectedComponent> select_lane_ccs_;
164 
165  base::Blob<float> lane_pos_blob_;
166  base::Blob<int> lane_hist_blob_;
167 };
168 
169 } // namespace camera
170 } // namespace perception
171 } // namespace apollo
Definition: common_functions.h:36
Definition: camera_frame.h:33
LaneType
Definition: denseline_lane_postprocessor.h:33
Definition: common_functions.h:234
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::vector< base::Point2DI > GetPixels() const
Definition: common_functions.h:255
LaneLineType
Definition: lane_struct.h:26
LaneLinePositionType
Definition of the position of a lane marking in respect to the ego lane.
Definition: lane_struct.h:34
DenselineLanePostprocessor()
Definition: denseline_lane_postprocessor.h:42
virtual ~DenselineLanePostprocessor()
Definition: denseline_lane_postprocessor.h:44
Definition: denseline_lane_postprocessor.h:40
bool Init(const char *binary_name)
Definition: base_lane_postprocessor.h:36
Definition: base_lane_postprocessor.h:34
Definition: base_lane_postprocessor.h:29