Apollo 10.0
自动驾驶开放平台
postprocess.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 *****************************************************************************/
17
18#include "cyber/common/log.h"
20
21namespace apollo {
22namespace perception {
23namespace camera {
24
25void GetCaddnObjects(std::vector<base::ObjectPtr> *objects,
26 const caddn::ModelParam &model_param,
27 const std::vector<base::ObjectSubType> &types,
28 const base::BlobPtr<float> &boxes,
29 const base::BlobPtr<float> &labels,
30 const base::BlobPtr<float> &scores) {
31 objects->clear();
32 const float *boxes_data = boxes->cpu_data();
33 const float *labels_data = labels->cpu_data();
34 const float *scores_data = scores->cpu_data();
35
36 int len_pred = 7;
37 for (int i = 0; i < labels->num(); ++i) {
38 const float *bbox = boxes_data + i * len_pred;
39 float score = *(scores_data + i);
40 if (score < model_param.score_threshold()) {
41 continue;
42 }
43
44 float label = *(labels_data + i);
45 base::ObjectPtr obj = nullptr;
46 obj.reset(new base::Object);
47 obj->sub_type = GetSubtype(label, types);
48 obj->type = base::kSubType2TypeMap.at(obj->sub_type);
49 obj->type_probs.assign(static_cast<int>(base::ObjectType::MAX_OBJECT_TYPE),
50 0);
51 obj->sub_type_probs.assign(
52 static_cast<int>(base::ObjectSubType::MAX_OBJECT_TYPE), 0);
53 obj->type_probs[static_cast<int>(obj->type)] = score;
54 obj->sub_type_probs[static_cast<int>(obj->sub_type)] = score;
55 obj->confidence = score;
56
57 // todo(zero): Need to be converted to camera coordinates and
58 // converted to KITTI coordinates
59 Eigen::Matrix<float, 3, 4> velo_to_cam;
60 velo_to_cam << 0.00753374, -0.9999714, -0.0006166, -0.00406977, 0.01480249,
61 0.00072807, -0.9998902, -0.07631618, 0.9998621, 0.00752379, 0.01480755,
62 -0.2717806;
63
64 Eigen::Matrix<float, 3, 3> R;
65 R << 0.9999239, 0.00983776, -0.00744505, -0.0098698, 0.9999421, -0.00427846,
66 0.00740253, 0.00435161, 0.9999631;
67
68 std::vector<float> test_result(7);
69 Bbox3dLidar2Camera(velo_to_cam, R, bbox, &test_result);
70
71 FillCaddnBbox3d(obj, test_result.data());
72
73 objects->push_back(obj);
74 }
75}
76
77void Bbox3dLidar2Camera(const Eigen::Matrix<float, 3, 4> &V2C,
78 const Eigen::Matrix<float, 3, 3> &R,
79 const float *bbox_lidar,
80 std::vector<float> *bbox_camera) {
81 float x = *(bbox_lidar + 0);
82 float y = *(bbox_lidar + 1);
83 float z = *(bbox_lidar + 2);
84 float l = *(bbox_lidar + 3);
85 float w = *(bbox_lidar + 4);
86 float h = *(bbox_lidar + 5);
87 float r = *(bbox_lidar + 6);
88 r = -r - M_PI / 2.0;
89 // 4*1
90 Eigen::Vector4f xyz_lidar;
91 xyz_lidar << x, y, z - h / 2.0, 1.0;
92 Eigen::Matrix<float, 1, 3> pts_rect =
93 xyz_lidar.transpose() * (V2C.transpose() * R.transpose());
94 std::vector<float> final_result{
95 pts_rect(0), pts_rect(1), pts_rect(2), l, h, w, r};
96 bbox_camera->assign(final_result.data(),
97 final_result.data() + final_result.size());
98}
99
101 const std::vector<base::ObjectSubType> &types) {
102 if (cls < 0 || cls >= static_cast<int>(types.size())) {
104 }
105
106 return types[cls];
107}
108
109void FillCaddnBbox3d(base::ObjectPtr obj, const float *bbox) {
110 obj->camera_supplement.alpha = bbox[6];
111 obj->size[2] = bbox[3];
112 obj->size[1] = bbox[4];
113 obj->size[0] = bbox[5];
114
115 obj->camera_supplement.local_center[0] = bbox[0];
116 obj->camera_supplement.local_center[1] = bbox[1];
117 obj->camera_supplement.local_center[2] = bbox[2];
118}
119
120} // namespace camera
121} // namespace perception
122} // namespace apollo
const std::map< ObjectSubType, ObjectType > kSubType2TypeMap
ObjectSubType mapping
std::shared_ptr< Object > ObjectPtr
Definition object.h:127
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition blob.h:313
void FillCaddnBbox3d(base::ObjectPtr obj, const float *bbox)
Add objects values to object
base::ObjectSubType GetSubtype(int cls, const std::vector< base::ObjectSubType > &types)
Get the Subtype
void Bbox3dLidar2Camera(const Eigen::Matrix< float, 3, 4 > &V2C, const Eigen::Matrix< float, 3, 3 > &R, const float *bbox_lidar, std::vector< float > *bbox_camera)
Get the Caddn Objects objects from Blob
void GetCaddnObjects(std::vector< base::ObjectPtr > *objects, const caddn::ModelParam &model_param, const std::vector< base::ObjectSubType > &types, const base::BlobPtr< float > &boxes, const base::BlobPtr< float > &labels, const base::BlobPtr< float > &scores)
Get the Caddn Objects objects from Blob
class register implement
Definition arena_queue.h:37