29
29
namespace object_recognition_utils
30
30
{
31
31
using tier4_autoware_utils::Polygon2d;
32
+ // minimum area to avoid division by zero
33
+ static const double MIN_AREA = 1e-6 ;
32
34
33
35
inline double getConvexShapeArea (const Polygon2d & source_polygon, const Polygon2d & target_polygon)
34
36
{
@@ -66,10 +68,12 @@ template <class T1, class T2>
66
68
double get2dIoU (const T1 source_object, const T2 target_object, const double min_union_area = 0.01 )
67
69
{
68
70
const auto source_polygon = tier4_autoware_utils::toPolygon2d (source_object);
71
+ if (boost::geometry::area (source_polygon) < MIN_AREA) return 0.0 ;
69
72
const auto target_polygon = tier4_autoware_utils::toPolygon2d (target_object);
73
+ if (boost::geometry::area (target_polygon) < MIN_AREA) return 0.0 ;
70
74
71
75
const double intersection_area = getIntersectionArea (source_polygon, target_polygon);
72
- if (intersection_area == 0.0 ) return 0.0 ;
76
+ if (intersection_area < MIN_AREA ) return 0.0 ;
73
77
const double union_area = getUnionArea (source_polygon, target_polygon);
74
78
75
79
const double iou =
@@ -81,7 +85,9 @@ template <class T1, class T2>
81
85
double get2dGeneralizedIoU (const T1 & source_object, const T2 & target_object)
82
86
{
83
87
const auto source_polygon = tier4_autoware_utils::toPolygon2d (source_object);
88
+ if (boost::geometry::area (source_polygon) < MIN_AREA) return 0.0 ;
84
89
const auto target_polygon = tier4_autoware_utils::toPolygon2d (target_object);
90
+ if (boost::geometry::area (target_polygon) < MIN_AREA) return 0.0 ;
85
91
86
92
const double intersection_area = getIntersectionArea (source_polygon, target_polygon);
87
93
const double union_area = getUnionArea (source_polygon, target_polygon);
@@ -95,11 +101,13 @@ template <class T1, class T2>
95
101
double get2dPrecision (const T1 source_object, const T2 target_object)
96
102
{
97
103
const auto source_polygon = tier4_autoware_utils::toPolygon2d (source_object);
104
+ const double source_area = boost::geometry::area (source_polygon);
105
+ if (source_area < MIN_AREA) return 0.0 ;
98
106
const auto target_polygon = tier4_autoware_utils::toPolygon2d (target_object);
107
+ if (boost::geometry::area (target_polygon) < MIN_AREA) return 0.0 ;
99
108
100
109
const double intersection_area = getIntersectionArea (source_polygon, target_polygon);
101
- if (intersection_area == 0.0 ) return 0.0 ;
102
- const double source_area = boost::geometry::area (source_polygon);
110
+ if (intersection_area < MIN_AREA) return 0.0 ;
103
111
104
112
return std::min (1.0 , intersection_area / source_area);
105
113
}
@@ -108,11 +116,13 @@ template <class T1, class T2>
108
116
double get2dRecall (const T1 source_object, const T2 target_object)
109
117
{
110
118
const auto source_polygon = tier4_autoware_utils::toPolygon2d (source_object);
119
+ if (boost::geometry::area (source_polygon) < MIN_AREA) return 0.0 ;
111
120
const auto target_polygon = tier4_autoware_utils::toPolygon2d (target_object);
121
+ const double target_area = boost::geometry::area (target_polygon);
122
+ if (target_area < MIN_AREA) return 0.0 ;
112
123
113
124
const double intersection_area = getIntersectionArea (source_polygon, target_polygon);
114
- if (intersection_area == 0.0 ) return 0.0 ;
115
- const double target_area = boost::geometry::area (target_polygon);
125
+ if (intersection_area < MIN_AREA) return 0.0 ;
116
126
117
127
return std::min (1.0 , intersection_area / target_area);
118
128
}
0 commit comments