Apollo 11.0
自动驾驶开放平台
feature_descriptor.h
浏览该文件的文档.
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 *****************************************************************************/
16#pragma once
17
18#include <algorithm>
19#include <limits>
20#include <vector>
21
23
24namespace apollo {
25namespace perception {
26namespace radar4d {
27
29 public:
30 explicit FeatureDescriptor(base::RadarPointFCloud* cloud) { cloud_ = cloud; }
31 FeatureDescriptor() : cloud_(nullptr) {}
32 ~FeatureDescriptor() = default;
33
34 void SetCloud(base::RadarPointFCloud* cloud) { cloud_ = cloud; }
35
36 void ComputeHistogram(int bin_size, float* feature) {
37 GetMinMaxCenter();
38 int xstep = bin_size;
39 int ystep = bin_size;
40 int zstep = bin_size;
41 int stat_len = xstep + ystep + zstep;
42 std::vector<int> stat_feat(stat_len, 0);
43 float xsize =
44 (max_pt_.x - min_pt_.x) / static_cast<float>(xstep) + 0.000001f;
45 float ysize =
46 (max_pt_.y - min_pt_.y) / static_cast<float>(ystep) + 0.000001f;
47 float zsize =
48 (max_pt_.z - min_pt_.z) / static_cast<float>(zstep) + 0.000001f;
49
50 int pt_num = static_cast<int>(cloud_->size());
51 for (int i = 0; i < pt_num; ++i) {
52 base::RadarPointF& pt = cloud_->at(i);
53 ++stat_feat[static_cast<int>((pt.x - min_pt_.x) / xsize)];
54 ++stat_feat[xstep + static_cast<int>((pt.y - min_pt_.y) / ysize)];
55 ++stat_feat[xstep + ystep + static_cast<int>((pt.z - min_pt_.z) / zsize)];
56 }
57
58 feature[0] = center_pt_.x / 10.0f;
59 feature[1] = center_pt_.y / 10.0f;
60 feature[2] = center_pt_.z;
61 feature[3] = xsize;
62 feature[4] = ysize;
63 feature[5] = zsize;
64 feature[6] = static_cast<float>(pt_num);
65 for (size_t i = 0; i < stat_feat.size(); ++i) {
66 feature[i + 7] =
67 static_cast<float>(stat_feat[i]) / static_cast<float>(pt_num);
68 }
69 }
70
71 private:
72 void GetMinMaxCenter() {
73 float xsum = 0.0f;
74 float ysum = 0.0f;
75 float zsum = 0.0f;
76 min_pt_.x = min_pt_.y = min_pt_.z = std::numeric_limits<float>::max();
77 max_pt_.x = max_pt_.y = max_pt_.z = -std::numeric_limits<float>::max();
78
79 float pt_num = static_cast<float>(cloud_->size());
80 for (int i = 0; i < static_cast<int>(pt_num); ++i) {
81 base::RadarPointF& pt = cloud_->at(i);
82 xsum += pt.x;
83 ysum += pt.y;
84 zsum += pt.z;
85 min_pt_.x = std::min(min_pt_.x, pt.x);
86 max_pt_.x = std::max(max_pt_.x, pt.x);
87 min_pt_.y = std::min(min_pt_.y, pt.y);
88 max_pt_.y = std::max(max_pt_.y, pt.y);
89 min_pt_.z = std::min(min_pt_.z, pt.z);
90 max_pt_.z = std::max(max_pt_.z, pt.z);
91 }
92
93 // center position
94 center_pt_.x = xsum / pt_num;
95 center_pt_.y = ysum / pt_num;
96 center_pt_.z = zsum / pt_num;
97 }
98
100 base::RadarPointF min_pt_;
101 base::RadarPointF max_pt_;
102 base::RadarPointF center_pt_;
103}; // class FeatureDescriptor
104
105} // namespace radar4d
106} // namespace perception
107} // namespace apollo
FeatureDescriptor(base::RadarPointFCloud *cloud)
void SetCloud(base::RadarPointFCloud *cloud)
void ComputeHistogram(int bin_size, float *feature)
AttributeRadarPointCloud< RadarPointF > RadarPointFCloud
RadarPoint< float > RadarPointF
Definition point.h:113
class register implement
Definition arena_queue.h:37