-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbounding_box_feature.cpp
More file actions
63 lines (56 loc) · 1.67 KB
/
bounding_box_feature.cpp
File metadata and controls
63 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2016 Baidu.com, Inc. All Rights Reserved
// @author erlangz(zhengwenchao@baidu.com)
// @date 2016/12/29 19:29:24
// @file bounding_box_feature.cpp
// @brief
//
#include "bounding_box_feature.h"
namespace adu {
namespace perception {
BoundingBoxFeature::BoundingBoxFeature() {
}
bool BoundingBoxFeature::min_max(const pcl::PointCloud<pcl::PointXYZ>::Ptr object,
Eigen::Vector3f& min, Eigen::Vector3f& max) {
//Get AABB
for (int i = 0; i < 3; i++) {
min(i) = FLT_MAX;
max(i) = -FLT_MAX;
}
for (int i = 0; i < object->points.size(); i++) {
if (object->points[i].x > max(0)) {
max(0) = object->points[i].x;
}
if (object->points[i].x < min(0)) {
min(0) = object->points[i].x;
}
if (object->points[i].y > max(1)) {
max(1) = object->points[i].y;
}
if (object->points[i].y < min(1)) {
min(1) = object->points[i].y;
}
if (object->points[i].z > max(2)) {
max(2) = object->points[i].z;
}
if (object->points[i].z < min(2)) {
min(2) = object->points[i].z;
}
}
return true;
}
bool BoundingBoxFeature::compute(const pcl::PointCloud<pcl::PointXYZ>::Ptr object,
std::vector<float>* bounding_box_feature) {
Eigen::Vector3f min;
Eigen::Vector3f max;
if(!min_max(object, min, max)) {
return false;
}
//Length, Width, Height
bounding_box_feature->resize(3, 0.0);
for (int i = 0; i < 3; i++) {
bounding_box_feature->at(i) = max(i) - min(i);
}
return true;
}
}
} // namespace adu