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