Apollo 10.0
自动驾驶开放平台
postprocess.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 <memory>
19
20#include "cyber/common/log.h"
21
22namespace apollo {
23namespace perception {
24namespace camera {
25
27 const std::vector<base::ObjectSubType> &types) {
28 if (cls < 0 || cls >= static_cast<int>(types.size())) {
30 }
31
32 return types[cls];
33}
34
36 const base::BlobPtr<float> &labels,
37 const base::BlobPtr<float> &scores,
38 const std::vector<base::ObjectSubType> &types,
39 float score_threshold, std::vector<base::ObjectPtr> *objects) {
40 const auto bbox_ptr = box3ds->cpu_data();
41 const auto label_ptr = labels->cpu_data();
42 const auto score_ptr = scores->cpu_data();
43
44 int feature_size = box3ds->shape(1);
45 objects->clear();
46 for (int i = 0; i < scores->count(); ++i) {
47 float score = score_ptr[i];
48 if (score < score_threshold) {
49 continue;
50 }
51
53 obj.reset(new base::Object());
54
55 obj->sub_type = GetSubtype(label_ptr[i], types);
56 obj->type = base::kSubType2TypeMap.at(obj->sub_type);
57 obj->type_probs.assign(static_cast<int>(base::ObjectType::MAX_OBJECT_TYPE),
58 0);
59 obj->sub_type_probs.assign(
60 static_cast<int>(base::ObjectSubType::MAX_OBJECT_TYPE), 0);
61 obj->type_probs[static_cast<int>(obj->type)] = score;
62 obj->sub_type_probs[static_cast<int>(obj->sub_type)] = score;
63 obj->confidence = score;
64
65 FillBBox3d(bbox_ptr + i * feature_size, obj);
66
67 objects->push_back(obj);
68 }
69}
70
71void FillBBox3d(const float *bbox, base::ObjectPtr obj) {
72 obj->camera_supplement.local_center[0] = bbox[0];
73 obj->camera_supplement.local_center[1] = bbox[1];
74 obj->camera_supplement.local_center[2] = bbox[2];
75 // size: length, width, height of bbox
76 obj->size[0] = bbox[4];
77 obj->size[1] = bbox[3];
78 obj->size[2] = bbox[5];
79
80 // yaw
81 obj->theta = bbox[6];
82
83 obj->center(0) = static_cast<double>(obj->camera_supplement.local_center[0]);
84 obj->center(1) = static_cast<double>(obj->camera_supplement.local_center[1]);
85 obj->center(2) = static_cast<double>(obj->camera_supplement.local_center[2]);
86}
87
88} // namespace camera
89} // namespace perception
90} // 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 FillBBox3d(const float *bbox, base::ObjectPtr obj)
Fill the 3d bbox to object
base::ObjectSubType GetSubtype(int cls, const std::vector< base::ObjectSubType > &types)
Get the Subtype
void GetObjects(const base::BlobPtr< float > &box3ds, const base::BlobPtr< float > &labels, const base::BlobPtr< float > &scores, const std::vector< base::ObjectSubType > &types, float score_threshold, std::vector< base::ObjectPtr > *objects)
Get the Objects objects from blob
class register implement
Definition arena_queue.h:37