pcod-common v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
pcod_common::BoundingBox Struct Reference

#include <bounding_box.hpp>

Public Member Functions

bool overlaps (const BoundingBox &other, float iou_threshold) const
 
float intersection_area (const BoundingBox &other) const
 
std::vector< BoundingBoxVertexrectangle_vertices () const
 

Public Attributes

std::array< float, 2 > center
 XY center in metres.
 
float z = 0.0f
 Z center in metres.
 
float length = 0.0f
 Length along the local X axis.
 
float width = 0.0f
 Width along the local Y axis.
 
float height = 0.0f
 Height along the Z axis.
 
float yaw = 0.0f
 Heading in radians.
 
float existence_probability = 0.0f
 Detection confidence.
 
std::vector< ClassificationEntryclassification
 Ranked semantic predictions.
 
bool has_velocity = false
 Whether velocity components are valid.
 
float v_x = 0.0f
 X velocity when has_velocity is true.
 
float v_y = 0.0f
 Y velocity when has_velocity is true.
 

Detailed Description

Oriented three-dimensional detection box and its semantic attributes.

Definition at line 63 of file bounding_box.hpp.

Member Function Documentation

◆ intersection_area()

float pcod_common::BoundingBox::intersection_area ( const BoundingBox & other) const
Parameters
otherBox to compare.
Returns
XY intersection area.

Definition at line 11 of file bounding_box.cpp.

11 {
12 auto rect1 = rectangle_vertices();
13 auto rect2 = other.rectangle_vertices();
14
15 std::vector<BoundingBoxVertex> intersection = rect1;
16
17 for (std::size_t i = 0; i < rect2.size(); ++i) {
18 if (intersection.size() <= 2) {
19 break;
20 }
21
22 Line line(rect2[i], rect2[(i + 1) % rect2.size()]);
23 std::vector<BoundingBoxVertex> new_intersection;
24 std::vector<float> line_values;
25
26 for (const auto& t : intersection) {
27 line_values.push_back(line(t));
28 }
29
30 for (std::size_t j = 0; j < intersection.size(); ++j) {
31 const BoundingBoxVertex& s = intersection[j];
32 const BoundingBoxVertex& t = intersection[(j + 1) % intersection.size()];
33 float s_value = line_values[j];
34 float t_value = line_values[(j + 1) % line_values.size()];
35
36 if (s_value <= 0) {
37 new_intersection.push_back(s);
38 }
39
40 if (s_value * t_value < 0) {
41 BoundingBoxVertex intersection_point = line.intersection(Line(s, t));
42 new_intersection.push_back(intersection_point);
43 }
44 }
45
46 intersection = new_intersection;
47 }
48
49 if (intersection.size() <= 2) {
50 return 0.0F;
51 }
52
53 float area = 0.0F;
54 for (std::size_t i = 0; i < intersection.size(); ++i) {
55 const BoundingBoxVertex& p = intersection[i];
56 const BoundingBoxVertex& q = intersection[(i + 1) % intersection.size()];
57 area += p.cross(q);
58 }
59
60 return 0.5F * std::abs(area);
61}
std::vector< BoundingBoxVertex > rectangle_vertices() const

References pcod_common::BoundingBoxVertex::cross(), pcod_common::Line::intersection(), and rectangle_vertices().

Referenced by main(), and overlaps().

◆ overlaps()

bool pcod_common::BoundingBox::overlaps ( const BoundingBox & other,
float iou_threshold ) const
Parameters
otherBox to compare.
iou_thresholdRequired IoU.
Returns
Whether the boxes overlap sufficiently.

Definition at line 63 of file bounding_box.cpp.

63 {
64 float intersection = intersection_area(other);
65 float union_area = length * width + other.length * other.width - intersection;
66 float iou = intersection / union_area;
67 return iou > iou_threshold;
68}
float length
Length along the local X axis.
float intersection_area(const BoundingBox &other) const
float width
Width along the local Y axis.

References intersection_area(), length, and width.

Referenced by main().

◆ rectangle_vertices()

std::vector< BoundingBoxVertex > pcod_common::BoundingBox::rectangle_vertices ( ) const

Return the four XY vertices in rectangle order.

Definition at line 70 of file bounding_box.cpp.

70 {
71 float angle = yaw;
72 float dx = length / 2.0F;
73 float dy = width / 2.0F;
74 float dxcos = dx * std::cos(angle);
75 float dxsin = dx * std::sin(angle);
76 float dycos = dy * std::cos(angle);
77 float dysin = dy * std::sin(angle);
78
79 std::vector<BoundingBoxVertex> vertices;
80 vertices.emplace_back(center[0] + (-dxcos - -dysin), center[1] + (-dxsin + -dycos));
81 vertices.emplace_back(center[0] + (dxcos - -dysin), center[1] + (dxsin + -dycos));
82 vertices.emplace_back(center[0] + (dxcos - dysin), center[1] + (dxsin + dycos));
83 vertices.emplace_back(center[0] + (-dxcos - dysin), center[1] + (-dxsin + dycos));
84 return vertices;
85}
std::array< float, 2 > center
XY center in metres.
float yaw
Heading in radians.

References center, length, width, and yaw.

Referenced by intersection_area().

Member Data Documentation

◆ center

std::array<float, 2> pcod_common::BoundingBox::center

XY center in metres.

Definition at line 64 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), main(), and rectangle_vertices().

◆ classification

std::vector<ClassificationEntry> pcod_common::BoundingBox::classification

Ranked semantic predictions.

Definition at line 71 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), and main().

◆ existence_probability

float pcod_common::BoundingBox::existence_probability = 0.0f

Detection confidence.

Definition at line 70 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), and main().

◆ has_velocity

bool pcod_common::BoundingBox::has_velocity = false

Whether velocity components are valid.

Definition at line 72 of file bounding_box.hpp.

◆ height

float pcod_common::BoundingBox::height = 0.0f

Height along the Z axis.

Definition at line 68 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod().

◆ length

float pcod_common::BoundingBox::length = 0.0f

Length along the local X axis.

Definition at line 66 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), main(), overlaps(), and rectangle_vertices().

◆ v_x

float pcod_common::BoundingBox::v_x = 0.0f

X velocity when has_velocity is true.

Definition at line 73 of file bounding_box.hpp.

◆ v_y

float pcod_common::BoundingBox::v_y = 0.0f

Y velocity when has_velocity is true.

Definition at line 74 of file bounding_box.hpp.

◆ width

float pcod_common::BoundingBox::width = 0.0f

Width along the local Y axis.

Definition at line 67 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), main(), overlaps(), and rectangle_vertices().

◆ yaw

float pcod_common::BoundingBox::yaw = 0.0f

Heading in radians.

Definition at line 69 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod(), and rectangle_vertices().

◆ z

float pcod_common::BoundingBox::z = 0.0f

Z center in metres.

Definition at line 65 of file bounding_box.hpp.

Referenced by pcod_common::DecodePbod().


The documentation for this struct was generated from the following files: