Apollo 11.0
自动驾驶开放平台
apollo::perception::lidar::OfflineLidarDetection类 参考
apollo::perception::lidar::OfflineLidarDetection 的协作图:

Public 成员函数

 OfflineLidarDetection ()=default
 
 ~OfflineLidarDetection ()=default
 
bool Init ()
 
bool TransformCloud (const base::PointFCloudPtr &local_cloud, const Eigen::Affine3d &pose, base::PointDCloudPtr world_cloud) const
 
bool Run ()
 
bool WriteObjectsForNewBenchmark (size_t frame_id, LidarFrame *frame, const std::string &path)
 

Protected 属性

std::unique_ptr< BaseLidarDetector > detector_
 
std::unique_ptr< ObjectBuilder > builder_
 

详细描述

在文件 offline_lidar_detection.cc 第 42 行定义.

构造及析构函数说明

◆ OfflineLidarDetection()

apollo::perception::lidar::OfflineLidarDetection::OfflineLidarDetection ( )
default

◆ ~OfflineLidarDetection()

apollo::perception::lidar::OfflineLidarDetection::~OfflineLidarDetection ( )
default

成员函数说明

◆ Init()

bool apollo::perception::lidar::OfflineLidarDetection::Init ( )
inline

在文件 offline_lidar_detection.cc 第 48 行定义.

48 {
49 BaseLidarDetector* detector =
50 BaseLidarDetectorRegisterer::GetInstanceByName(FLAGS_detector_name);
51 CHECK_NOTNULL(detector);
52 detector_.reset(detector);
53
54 LidarDetectorInitOptions detection_init_options;
55 detection_init_options.sensor_name = FLAGS_sensor_name;
56 detection_init_options.config_path = FLAGS_config_path;
57 detection_init_options.config_file = FLAGS_config_file;
58 ACHECK(detector_->Init(detection_init_options))
59 << "lidar detector init error";
60
61 ObjectBuilderInitOptions builder_init_options;
62 builder_.reset(new ObjectBuilder);
63 ACHECK(builder_->Init(builder_init_options));
64
65 return true;
66 }
#define ACHECK(cond)
Definition log.h:80

◆ Run()

bool apollo::perception::lidar::OfflineLidarDetection::Run ( )
inline

在文件 offline_lidar_detection.cc 第 92 行定义.

92 {
93 std::string pcd_folder = FLAGS_pcd_path;
94 std::vector<std::string> pcd_file_names;
95 if (!algorithm::GetFileList(pcd_folder, ".pcd", &pcd_file_names)) {
96 AERROR << "pcd_folder: " << pcd_folder << " get file list error.";
97 return false;
98 }
99
100 std::sort(pcd_file_names.begin(), pcd_file_names.end(),
101 [](const std::string& lhs, const std::string& rhs) {
102 if (lhs.length() != rhs.length()) {
103 return lhs.length() < rhs.length();
104 }
105 return lhs <= rhs;
106 });
107
108 for (size_t i = 0; i < pcd_file_names.size(); ++i) {
109 AINFO << "***************** Frame " << i << " ******************";
110 AINFO << pcd_file_names[i];
111
112 std::shared_ptr<LidarFrame> frame = LidarFramePool::Instance().Get();
113 if (frame->cloud == nullptr) {
114 frame->cloud = base::PointFCloudPool::Instance().Get();
115 }
116 if (frame->world_cloud == nullptr) {
117 frame->world_cloud = base::PointDCloudPool::Instance().Get();
118 }
119 LoadPCLPCD(pcd_file_names[i], frame->cloud.get());
120 // frame->lidar2world_pose is default identity matrix
121 TransformCloud(frame->cloud, frame->lidar2world_pose, frame->world_cloud);
122 AINFO << "Read point cloud from " << pcd_file_names[i]
123 << " with cloud size: " << frame->cloud->size();
124
125 LidarDetectorOptions detection_options;
126 if (!detector_->Detect(detection_options, frame.get())) {
127 AERROR << "Lidar detector detect error!";
128 return false;
129 }
130
131 ObjectBuilderOptions builder_options;
132 if (!builder_->Build(builder_options, frame.get())) {
133 AERROR << "Lidar detector, object builder error.";
134 return false;
135 }
136
137 std::string output_path = FLAGS_output_path;
138 WriteObjectsForNewBenchmark(i, frame.get(), output_path);
139 }
140
141 return true;
142 }
std::shared_ptr< ObjectType > Get() override
bool TransformCloud(const base::PointFCloudPtr &local_cloud, const Eigen::Affine3d &pose, base::PointDCloudPtr world_cloud) const
bool WriteObjectsForNewBenchmark(size_t frame_id, LidarFrame *frame, const std::string &path)
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetFileList(const std::string &path, const std::string &suffix, std::vector< std::string > *files)
Definition io_util.cc:163
bool LoadPCLPCD(const std::string &file_path, base::PointFCloud *cloud_out)
Definition pcl_util.h:54

◆ TransformCloud()

bool apollo::perception::lidar::OfflineLidarDetection::TransformCloud ( const base::PointFCloudPtr &  local_cloud,
const Eigen::Affine3d &  pose,
base::PointDCloudPtr  world_cloud 
) const
inline

在文件 offline_lidar_detection.cc 第 68 行定义.

70 {
71 if (local_cloud == nullptr) {
72 return false;
73 }
74 world_cloud->clear();
75 world_cloud->reserve(local_cloud->size());
76 for (size_t i = 0; i < local_cloud->size(); ++i) {
77 auto& pt = local_cloud->at(i);
78 Eigen::Vector3d trans_point(pt.x, pt.y, pt.z);
79 trans_point = pose * trans_point;
80 base::PointD world_point;
81 world_point.x = trans_point(0);
82 world_point.y = trans_point(1);
83 world_point.z = trans_point(2);
84 world_point.intensity = pt.intensity;
85 world_cloud->push_back(world_point, local_cloud->points_timestamp(i),
86 std::numeric_limits<float>::max(),
87 local_cloud->points_beam_id()[i], 0);
88 }
89 return true;
90 }
Point< double > PointD
Definition point.h:57

◆ WriteObjectsForNewBenchmark()

bool apollo::perception::lidar::OfflineLidarDetection::WriteObjectsForNewBenchmark ( size_t  frame_id,
LidarFrame *  frame,
const std::string &  path 
)
inline

在文件 offline_lidar_detection.cc 第 144 行定义.

145 {
147 AERROR << "Failed to create: " << path;
148 return false;
149 }
150 std::ofstream fout;
151 fout.open(absl::StrCat(path, "/", frame_id, ".txt"));
152 fout << frame_id << " " << frame->segmented_objects.size() << std::endl;
153
154 for (auto& object : frame->segmented_objects) {
155 fout << "velodyne_64"
156 << " " << object->id << " " << object->track_id << " "
157 << object->lidar_supplement.is_background << " "
158 << std::setprecision(8) << object->confidence << " ";
159
160 std::string type = "unknow";
161 if (object->type == base::ObjectType::UNKNOWN ||
162 object->type == base::ObjectType::UNKNOWN_MOVABLE ||
163 object->type == base::ObjectType::UNKNOWN_UNMOVABLE) {
164 // type is unknow in this case
165 } else if (object->type == base::ObjectType::PEDESTRIAN) {
166 type = "pedestrian";
167 } else if (object->type == base::ObjectType::VEHICLE) {
168 type = "smallMot";
169 } else if (object->type == base::ObjectType::BICYCLE) {
170 type = "nonMot";
171 }
172
173 double yaw = atan2(object->direction(1), object->direction(0));
174 auto& object_cloud = object->lidar_supplement.cloud;
175
176 fout << type << " " << object->center(0) << " " << object->center(1)
177 << " " << object->center(2) << " " << object->size(0) << " "
178 << object->size(1) << " " << object->size(2) << " "
179 << yaw /*yaw*/ << " " << 0 /*roll*/ << " " << 0 /*pitch*/ << " "
180 << 0 /*truncated*/ << " " << 0 /*occluded*/ << " "
181 << object->velocity(0) << " " << object->velocity(1) << " "
182 << object->velocity(2) << " ";
183 fout << object_cloud.size() << " ";
184 for (size_t i = 0; i < object_cloud.size(); ++i) {
185 auto& pt = object_cloud.at(i);
186 fout << std::setprecision(8) << pt.x << " " << pt.y << " " << pt.z
187 << " " << pt.intensity << " ";
188 }
189 // fout << 0/*#indices*/ << " ";
190 // we save polygon here for debug
191 int polygon_size = -static_cast<int>(object->polygon.size());
192 fout << polygon_size /*negative polygon size*/ << " ";
193 for (size_t i = 0; i < object->polygon.size(); ++i) {
194 const auto& pt = object->polygon[i];
195 fout << std::setprecision(8) << pt.x << " " << pt.y << " " << pt.z
196 << " ";
197 }
198 fout << std::endl;
199 }
200
201 fout.close();
202 return true;
203 }
bool EnsureDirectory(const std::string &directory_path)
Check if a specified directory specified by directory_path exists.
Definition file.cc:285
std::string frame_id
Point cloud frame id

类成员变量说明

◆ builder_

std::unique_ptr<ObjectBuilder> apollo::perception::lidar::OfflineLidarDetection::builder_
protected

在文件 offline_lidar_detection.cc 第 207 行定义.

◆ detector_

std::unique_ptr<BaseLidarDetector> apollo::perception::lidar::OfflineLidarDetection::detector_
protected

在文件 offline_lidar_detection.cc 第 206 行定义.


该类的文档由以下文件生成: