Apollo  6.0
Open source self driving car software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <limits>
23 #include <map>
24 #include <string>
25 #include <tuple>
26 #include <unordered_set>
27 #include <vector>
28 
29 #include "Eigen/Core"
30 
32 
33 namespace apollo {
34 namespace perception {
35 namespace lidar {
36 
37 class LRClassifier {
38  public:
39  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
40 
41  public:
42  LRClassifier() = default;
44  bool init() {
45  _lr_parameters.resize(3, 4);
46  _lr_parameters.coeffRef(0, 0) = 0.0510903f;
47  _lr_parameters.coeffRef(0, 1) = -1.00989f;
48  _lr_parameters.coeffRef(0, 2) = -1.6537f;
49  _lr_parameters.coeffRef(0, 3) = 0.130055f;
50  _lr_parameters.coeffRef(1, 0) = 0.266469f;
51  _lr_parameters.coeffRef(1, 1) = -0.538964f;
52  _lr_parameters.coeffRef(1, 2) = -0.291611f;
53  _lr_parameters.coeffRef(1, 3) = -0.070701f;
54  _lr_parameters.coeffRef(2, 0) = 0.497949f;
55  _lr_parameters.coeffRef(2, 1) = -0.504843f;
56  _lr_parameters.coeffRef(2, 2) = -0.152141f;
57  _lr_parameters.coeffRef(2, 3) = -1.38024f;
58  return true;
59  }
60 
61  std::string GetLabel(base::PointFCloudConstPtr cloud) {
62  // point cloud should be rotated
63  float x_max = -std::numeric_limits<float>::max();
64  float y_max = -std::numeric_limits<float>::max();
65  float z_max = -std::numeric_limits<float>::max();
66  float x_min = std::numeric_limits<float>::max();
67  float y_min = std::numeric_limits<float>::max();
68  float z_min = std::numeric_limits<float>::max();
69  for (size_t i = 0; i < cloud->size(); ++i) {
70  auto pt = (*cloud)[i];
71  x_min = std::min(x_min, pt.x);
72  x_max = std::max(x_max, pt.x);
73  y_min = std::min(y_min, pt.y);
74  y_max = std::max(y_max, pt.y);
75  z_min = std::min(z_min, pt.z);
76  z_max = std::max(z_max, pt.z);
77  }
78  Eigen::Vector3f fea = {x_max - x_min, y_max - y_min, z_max - z_min};
79  Eigen::VectorXf response = fea.transpose() * _lr_parameters;
80  int type = 0;
81  // float max_score = response.maxCoeff(&type);
82  return _labels[type];
83  }
84 
85  private:
86  Eigen::MatrixXf _lr_parameters;
87  std::vector<std::string> _labels = {"unknown", "nonMot", "pedestrian",
88  "smallMot"};
89 };
90 
91 } // namespace lidar
92 } // namespace perception
93 } // namespace apollo
bool init()
Definition: lr_classifier.h:44
Eigen::Vector3f Vector3f
Definition: base_map_fwd.h:29
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::string GetLabel(base::PointFCloudConstPtr cloud)
Definition: lr_classifier.h:61
std::shared_ptr< const PointFCloud > PointFCloudConstPtr
Definition: point_cloud.h:483
Definition: lr_classifier.h:37
~LRClassifier()
Definition: lr_classifier.h:43