Skip to content

Commit

Permalink
fix(object_recognition_utils): check polygon area on iou calculation (#…
Browse files Browse the repository at this point in the history
…6701)

* feat(object_recognition_utils): check input polygon on IoU calculations

Signed-off-by: Taekjin LEE <[email protected]>

* fix: MIN_AREA close to the epsilon of float 1e-6

Signed-off-by: Taekjin LEE <[email protected]>

---------

Signed-off-by: Taekjin LEE <[email protected]>
  • Loading branch information
technolojin authored Apr 2, 2024
1 parent 8948859 commit 1aa5bb9
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
namespace object_recognition_utils
{
using tier4_autoware_utils::Polygon2d;
// minimum area to avoid division by zero
static const double MIN_AREA = 1e-6;

inline double getConvexShapeArea(const Polygon2d & source_polygon, const Polygon2d & target_polygon)
{
Expand Down Expand Up @@ -66,10 +68,12 @@ template <class T1, class T2>
double get2dIoU(const T1 source_object, const T2 target_object, const double min_union_area = 0.01)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
if (intersection_area < MIN_AREA) return 0.0;
const double union_area = getUnionArea(source_polygon, target_polygon);

const double iou =
Expand All @@ -81,7 +85,9 @@ template <class T1, class T2>
double get2dGeneralizedIoU(const T1 & source_object, const T2 & target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
const double union_area = getUnionArea(source_polygon, target_polygon);
Expand All @@ -95,11 +101,13 @@ template <class T1, class T2>
double get2dPrecision(const T1 source_object, const T2 target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
const double source_area = boost::geometry::area(source_polygon);
if (source_area < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
if (boost::geometry::area(target_polygon) < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
const double source_area = boost::geometry::area(source_polygon);
if (intersection_area < MIN_AREA) return 0.0;

return std::min(1.0, intersection_area / source_area);
}
Expand All @@ -108,11 +116,13 @@ template <class T1, class T2>
double get2dRecall(const T1 source_object, const T2 target_object)
{
const auto source_polygon = tier4_autoware_utils::toPolygon2d(source_object);
if (boost::geometry::area(source_polygon) < MIN_AREA) return 0.0;
const auto target_polygon = tier4_autoware_utils::toPolygon2d(target_object);
const double target_area = boost::geometry::area(target_polygon);
if (target_area < MIN_AREA) return 0.0;

const double intersection_area = getIntersectionArea(source_polygon, target_polygon);
if (intersection_area == 0.0) return 0.0;
const double target_area = boost::geometry::area(target_polygon);
if (intersection_area < MIN_AREA) return 0.0;

return std::min(1.0, intersection_area / target_area);
}
Expand Down

0 comments on commit 1aa5bb9

Please sign in to comment.