Skip to content

Commit 2f07d2f

Browse files
tzhong518pre-commit-ci[bot]
authored and
KhalilSelyan
committed
feat(pointpainting_fusion): add test for painting util (#7169)
* add: unit test for inside bbox func Signed-off-by: tzhong518 <sworgun@gmail.com> * style(pre-commit): autofix * fix: correct param name Signed-off-by: tzhong518 <sworgun@gmail.com> * add: comment Signed-off-by: tzhong518 <sworgun@gmail.com> --------- Signed-off-by: tzhong518 <sworgun@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5972592 commit 2f07d2f

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

perception/image_projection_based_fusion/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ if(BUILD_TESTING)
172172
ament_auto_add_gtest(test_geometry
173173
test/test_geometry.cpp
174174
)
175+
# test needed cuda, tensorRT and cudnn
176+
if(TRT_AVAIL AND CUDA_AVAIL AND CUDNN_AVAIL)
177+
ament_auto_add_gtest(test_pointpainting
178+
test/test_pointpainting_fusion.cpp
179+
)
180+
endif()
181+
175182
endif()
176183

177184
ament_auto_package(INSTALL_TO_SHARE

perception/image_projection_based_fusion/include/image_projection_based_fusion/pointpainting_fusion/node.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ namespace image_projection_based_fusion
3333
{
3434
using Label = autoware_perception_msgs::msg::ObjectClassification;
3535

36+
inline bool isInsideBbox(
37+
float proj_x, float proj_y, sensor_msgs::msg::RegionOfInterest roi, float zc)
38+
{
39+
// z_c is scaling to normalize projection point
40+
return proj_x >= roi.x_offset * zc && proj_x <= (roi.x_offset + roi.width) * zc &&
41+
proj_y >= roi.y_offset * zc && proj_y <= (roi.y_offset + roi.height) * zc;
42+
}
43+
3644
class PointPaintingFusionNode
3745
: public FusionNode<sensor_msgs::msg::PointCloud2, DetectedObjects, DetectedObjectsWithFeature>
3846
{

perception/image_projection_based_fusion/src/pointpainting_fusion/node.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ Eigen::Affine3f _transformToEigen(const geometry_msgs::msg::Transform & t)
4545
namespace image_projection_based_fusion
4646
{
4747

48-
inline bool isInsideBbox(
49-
float proj_x, float proj_y, sensor_msgs::msg::RegionOfInterest roi, float zc)
50-
{
51-
return proj_x >= roi.x_offset * zc && proj_x <= (roi.x_offset + roi.width) * zc &&
52-
proj_y >= roi.y_offset * zc && proj_y <= (roi.y_offset + roi.height) * zc;
53-
}
54-
5548
inline bool isVehicle(int label2d)
5649
{
5750
return label2d == autoware_perception_msgs::msg::ObjectClassification::CAR ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <image_projection_based_fusion/pointpainting_fusion/node.hpp>
16+
17+
#include <gtest/gtest.h>
18+
19+
sensor_msgs::msg::RegionOfInterest createRoi(
20+
const int32_t x_offset, const int32_t y_offset, const int32_t width, const int32_t height)
21+
{
22+
sensor_msgs::msg::RegionOfInterest roi;
23+
roi.x_offset = x_offset;
24+
roi.y_offset = y_offset;
25+
roi.width = width;
26+
roi.height = height;
27+
return roi;
28+
}
29+
30+
TEST(isInsideBboxTest, Inside)
31+
{
32+
const sensor_msgs::msg::RegionOfInterest roi = createRoi(20, 20, 10, 10);
33+
bool result = image_projection_based_fusion::isInsideBbox(25.0, 25.0, roi, 1.0);
34+
EXPECT_TRUE(result);
35+
}
36+
37+
TEST(isInsideBboxTest, Border)
38+
{
39+
const sensor_msgs::msg::RegionOfInterest roi = createRoi(20, 20, 10, 10);
40+
bool result = image_projection_based_fusion::isInsideBbox(20.0, 30.0, roi, 1.0);
41+
EXPECT_TRUE(result);
42+
}
43+
44+
TEST(isInsideBboxTest, Outside)
45+
{
46+
const sensor_msgs::msg::RegionOfInterest roi = createRoi(20, 20, 10, 10);
47+
bool result = image_projection_based_fusion::isInsideBbox(15.0, 15.0, roi, 1.0);
48+
EXPECT_FALSE(result);
49+
}
50+
51+
TEST(isInsideBboxTest, Zero)
52+
{
53+
const sensor_msgs::msg::RegionOfInterest roi = createRoi(0, 0, 0, 0);
54+
bool result = image_projection_based_fusion::isInsideBbox(0.0, 0.0, roi, 1.0);
55+
EXPECT_TRUE(result);
56+
}

0 commit comments

Comments
 (0)