-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(image_projection_based_fusion): add test for image_projection_ba…
…sed_fusion's IoU calculation functions (#7087) * added test for geometry utils iou calculation Signed-off-by: samrat.thapa <[email protected]> * style(pre-commit): autofix * fix pre-commit ci Signed-off-by: samrat.thapa <[email protected]> * fixed spelling errors Signed-off-by: samrat.thapa <[email protected]> --------- Signed-off-by: samrat.thapa <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c696905
commit be9a2b8
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
perception/image_projection_based_fusion/test/test_calc_iou_functions.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |