From a1db3ae8a1ce1589036feca7185e842d9401d63f Mon Sep 17 00:00:00 2001 From: BISTU-gzy <269895055+BISTU-gzy@users.noreply.github.com> Date: Sun, 12 Apr 2026 21:15:22 +0800 Subject: [PATCH] Perception: fix camera location refinement ROI symmetry --- .../camera_location_refinement/BUILD | 13 +++++ .../location_refiner_postprocessor.h | 6 +- .../location_refiner_postprocessor_test.cc | 55 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor_test.cc diff --git a/modules/perception/camera_location_refinement/BUILD b/modules/perception/camera_location_refinement/BUILD index 51fa135a073..8d703d80265 100644 --- a/modules/perception/camera_location_refinement/BUILD +++ b/modules/perception/camera_location_refinement/BUILD @@ -38,6 +38,19 @@ apollo_cc_library( "//modules/perception/common/camera:apollo_perception_common_camera", "//modules/perception/common/lib:apollo_perception_common_lib", "//modules/perception/common/onboard:apollo_perception_common_onboard", + "@com_google_googletest//:gtest", + ], +) + +apollo_cc_test( + name = "location_refiner_postprocessor_test", + size = "small", + srcs = [ + "location_refiner/location_refiner_postprocessor_test.cc", + ], + deps = [ + ":apollo_perception_camera_location_refinement", + "@com_google_googletest//:gtest_main", ], ) diff --git a/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor.h b/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor.h index d94d68b7b28..0d94b6a420b 100644 --- a/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor.h +++ b/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor.h @@ -18,6 +18,8 @@ #include #include +#include "gtest/gtest_prod.h" + #include "modules/perception/camera_location_refinement/location_refiner/proto/location_refiner.pb.h" #include "modules/perception/camera_location_refinement/interface/base_postprocessor.h" @@ -68,11 +70,13 @@ class LocationRefinerPostprocessor : public BasePostprocessor { float img_w_half = img_w / 2.0f; float slope = img_w_half * algorithm::IRec(img_h - h_down - v); float left = img_w_half - slope * (y - v); - float right = img_w_half + slope * (y - h_down); + float right = img_w_half + slope * (y - v); return x > left && x < right; } private: + FRIEND_TEST(LocationRefinerPostprocessorTest, roi_is_symmetric_test); + std::unique_ptr postprocessor_; std::shared_ptr calibration_service_; location_refiner::LocationRefinerParam location_refiner_param_; diff --git a/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor_test.cc b/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor_test.cc new file mode 100644 index 00000000000..781bf708b58 --- /dev/null +++ b/modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor_test.cc @@ -0,0 +1,55 @@ +/****************************************************************************** + * Copyright 2026 The Apollo Authors. All Rights Reserved. + * + * 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 "modules/perception/camera_location_refinement/location_refiner/location_refiner_postprocessor.h" + +#include "gtest/gtest.h" + +namespace apollo { +namespace perception { +namespace camera { + +class LocationRefinerPostprocessorTest : public ::testing::Test {}; + +TEST_F(LocationRefinerPostprocessorTest, roi_is_symmetric_test) { + LocationRefinerPostprocessor postprocessor; + + constexpr float kImageWidth = 1920.0f; + constexpr float kImageHeight = 1080.0f; + constexpr float kVanishingRow = 540.0f; + constexpr float kBottomMargin = 270.0f; + constexpr float kSampleRow = 675.0f; + + const float inside_left[2] = {500.0f, kSampleRow}; + const float inside_right[2] = {kImageWidth - inside_left[0], kSampleRow}; + const float outside_left[2] = {420.0f, kSampleRow}; + const float outside_right[2] = {kImageWidth - outside_left[0], kSampleRow}; + + EXPECT_TRUE(postprocessor.is_in_roi(inside_left, kImageWidth, kImageHeight, + kVanishingRow, kBottomMargin)); + EXPECT_TRUE(postprocessor.is_in_roi(inside_right, kImageWidth, kImageHeight, + kVanishingRow, kBottomMargin)); + EXPECT_FALSE(postprocessor.is_in_roi(outside_left, kImageWidth, + kImageHeight, kVanishingRow, + kBottomMargin)); + EXPECT_FALSE(postprocessor.is_in_roi(outside_right, kImageWidth, + kImageHeight, kVanishingRow, + kBottomMargin)); +} + +} // namespace camera +} // namespace perception +} // namespace apollo