Skip to content

Commit

Permalink
Add test_panel_simple_detector_plugin and test_data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ar-Ray-code committed Jan 3, 2024
1 parent 3e83096 commit 25a1574
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
7 changes: 5 additions & 2 deletions detector2d_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)

set(TEST_TARGETS
test_publish_center_plugin)
test_publish_center_plugin
test_panel_simple_detector_plugin)
foreach(TARGET ${TEST_TARGETS})
ament_add_gtest(${TARGET} test/src/${TARGET}.cpp)
target_link_libraries(${TARGET} ${PROJECT_NAME} ${OpenCV_LIBRARIES})
Expand All @@ -35,4 +36,6 @@ endif()
pluginlib_export_plugin_description_file(detector2d_base detector2d_plugins.xml)

include_directories(include)
ament_auto_package()
ament_auto_package(INSTALL_TO_SHARE
test/test_data
)
57 changes: 57 additions & 0 deletions detector2d_plugins/test/src/test_panel_simple_detector_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <ament_index_cpp/get_package_share_directory.hpp>
#include <gtest/gtest.h>
#include <opencv2/opencv.hpp>
#include <detector2d_base/detector2d_base.hpp>
#include <detector2d_param/detector2d_param.hpp>
#include <detector2d_plugins/panel_simple_detector.hpp>
#include <rclcpp/rclcpp.hpp>

class TestDetector2dClass : public ::testing::Test
{
protected:
std::unique_ptr<detector2d_plugins::PanelSimpleDetector> target_class_;
std::shared_ptr<detector2d_parameters::ParamListener> param_listener_;

std::string image_path;

virtual void SetUp()
{
rclcpp::init(0, nullptr);
auto node = std::make_shared<rclcpp::Node>("test_node");

this->image_path = ament_index_cpp::get_package_share_directory("detector2d_plugins") +
"/test_data/dark_00.png";

this->target_class_ =
std::make_unique<detector2d_plugins::PanelSimpleDetector>();

this->param_listener_ =
std::make_shared<detector2d_parameters::ParamListener>(
node->get_node_parameters_interface());
this->target_class_->init(*this->param_listener_);
}
};

TEST_F(TestDetector2dClass, test_default)
{
cv::Mat3b image = cv::imread(this->image_path, cv::IMREAD_COLOR);
auto result = this->target_class_->detect(image);

// bboxes [0]: 468, 328
// bboxes [1]: 632, 325
// bboxes [2]: 882, 345 <-- remove
// bboxes [3]: 797, 298
// bboxes [4]: 555, 228

ASSERT_EQ(result.detections[0].bbox.center.position.x, 468);
ASSERT_EQ(result.detections[0].bbox.center.position.y, 328);

ASSERT_EQ(result.detections[1].bbox.center.position.x, 632);
ASSERT_EQ(result.detections[1].bbox.center.position.y, 325);

ASSERT_EQ(result.detections[3].bbox.center.position.x, 797);
ASSERT_EQ(result.detections[3].bbox.center.position.y, 298);

ASSERT_EQ(result.detections[4].bbox.center.position.x, 555);
ASSERT_EQ(result.detections[4].bbox.center.position.y, 228);
}
Binary file added detector2d_plugins/test/test_data/dark_00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 25a1574

Please sign in to comment.