Apollo  v5.5.0
Open source self driving car software
lr_classifier.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 <cmath>
20 #include <cstdlib>
21 #include <iostream>
22 #include <map>
23 #include <string>
24 #include <tuple>
25 #include <unordered_set>
26 #include <vector>
27 
28 #include "Eigen/Core"
29 
31 
32 namespace apollo {
33 namespace perception {
34 namespace lidar {
35 
36 class LRClassifier {
37  public:
38  LRClassifier() = default;
40  bool init() {
41  _lr_parameters.resize(3, 4);
42  _lr_parameters.coeffRef(0, 0) = 0.0510903f;
43  _lr_parameters.coeffRef(0, 1) = -1.00989f;
44  _lr_parameters.coeffRef(0, 2) = -1.6537f;
45  _lr_parameters.coeffRef(0, 3) = 0.130055f;
46  _lr_parameters.coeffRef(1, 0) = 0.266469f;
47  _lr_parameters.coeffRef(1, 1) = -0.538964f;
48  _lr_parameters.coeffRef(1, 2) = -0.291611f;
49  _lr_parameters.coeffRef(1, 3) = -0.070701f;
50  _lr_parameters.coeffRef(2, 0) = 0.497949f;
51  _lr_parameters.coeffRef(2, 1) = -0.504843f;
52  _lr_parameters.coeffRef(2, 2) = -0.152141f;
53  _lr_parameters.coeffRef(2, 3) = -1.38024f;
54  return true;
55  }
56 
57  std::string GetLabel(base::PointFCloudConstPtr cloud) {
58  // point cloud should be rotated
59  float x_max = -FLT_MAX;
60  float y_max = -FLT_MAX;
61  float z_max = -FLT_MAX;
62  float x_min = FLT_MAX;
63  float y_min = FLT_MAX;
64  float z_min = FLT_MAX;
65  for (size_t i = 0; i < cloud->size(); ++i) {
66  auto pt = (*cloud)[i];
67  x_min = std::min(x_min, pt.x);
68  x_max = std::max(x_max, pt.x);
69  y_min = std::min(y_min, pt.y);
70  y_max = std::max(y_max, pt.y);
71  z_min = std::min(z_min, pt.z);
72  z_max = std::max(z_max, pt.z);
73  }
74  Eigen::Vector3f fea = {x_max - x_min, y_max - y_min, z_max - z_min};
75  Eigen::VectorXf response = fea.transpose() * _lr_parameters;
76  int type = 0;
77  // float max_score = response.maxCoeff(&type);
78  return _labels[type];
79  }
80 
81  private:
82  Eigen::MatrixXf _lr_parameters;
83  std::vector<std::string> _labels = {"unknown", "nonMot", "pedestrian",
84  "smallMot"};
85 };
86 
87 } // namespace lidar
88 } // namespace perception
89 } // namespace apollo
bool init()
Definition: lr_classifier.h:40
Definition: blob.h:72
std::string GetLabel(base::PointFCloudConstPtr cloud)
Definition: lr_classifier.h:57
std::shared_ptr< const PointFCloud > PointFCloudConstPtr
Definition: point_cloud.h:473
Definition: lr_classifier.h:36
~LRClassifier()
Definition: lr_classifier.h:39