Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(image_projection_based_fusion): add test for image_projection_based_fusion's IoU calculation functions #7087

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions perception/image_projection_based_fusion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ else()
message("Skipping build of some nodes due to missing dependencies")
endif()

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
ament_auto_add_gtest(test_calc_iou_functions
test/test_calc_iou_functions.cpp
)
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "image_projection_based_fusion/utils/geometry.hpp"

#include <gtest/gtest.h>

using image_projection_based_fusion::calcIoU;
using image_projection_based_fusion::calcIoUX;
using image_projection_based_fusion::calcIoUY;

TEST(GeometryTest, CalcIoU)
{
sensor_msgs::msg::RegionOfInterest roi1, roi2;

// Overlapping ROIs
roi1.x_offset = 0;
roi1.y_offset = 0;
roi1.width = 4;
roi1.height = 4;

roi2.x_offset = 2;
roi2.y_offset = 2;
roi2.width = 4;
roi2.height = 4;

double iou = calcIoU(roi1, roi2);
EXPECT_NEAR(iou, 1.0 / 7.0, 1e-6);

// Non-overlapping ROIs
roi2.x_offset = 5;
roi2.y_offset = 5;

iou = calcIoU(roi1, roi2);
EXPECT_EQ(iou, 0.0);

// Zero area ROI
roi1.width = 0;
roi1.height = 0;

iou = calcIoU(roi1, roi2);
EXPECT_EQ(iou, 0.0);
}

TEST(GeometryTest, CalcIoUX)
{
sensor_msgs::msg::RegionOfInterest roi1, roi2;

// Overlapping ROIs on x-axis
roi1.x_offset = 0;
roi1.y_offset = 0;
roi1.width = 4;
roi1.height = 4;

roi2.x_offset = 2;
roi2.y_offset = 0;
roi2.width = 4;
roi2.height = 4;

double iou_x = calcIoUX(roi1, roi2);
EXPECT_NEAR(iou_x, 2.0 / 6.0, 1e-6);

// Non-overlapping ROIs on x-axis
roi2.x_offset = 5;

iou_x = calcIoUX(roi1, roi2);
EXPECT_EQ(iou_x, 0.0);

// Zero width ROI
roi1.width = 0;

iou_x = calcIoUX(roi1, roi2);
EXPECT_EQ(iou_x, 0.0);
}

TEST(GeometryTest, CalcIoUY)
{
sensor_msgs::msg::RegionOfInterest roi1, roi2;

// Overlapping ROIs on y-axis
roi1.x_offset = 0;
roi1.y_offset = 0;
roi1.width = 4;
roi1.height = 4;

roi2.x_offset = 0;
roi2.y_offset = 2;
roi2.width = 4;
roi2.height = 4;

double iou_y = calcIoUY(roi1, roi2);
EXPECT_NEAR(iou_y, 2.0 / 6.0, 1e-6);

// Non-overlapping ROIs on y-axis
roi2.y_offset = 5;

iou_y = calcIoUY(roi1, roi2);
EXPECT_EQ(iou_y, 0.0);

// Zero height ROI
roi1.height = 0;

iou_y = calcIoUY(roi1, roi2);
EXPECT_EQ(iou_y, 0.0);
}

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading