38 #include <gtest/gtest.h>
40 #include <opencv2/core/core.hpp>
42 #include <sensor_msgs/CameraInfo.h>
44 #include <geometry_msgs/TransformStamped.h>
56 "moveit_calibration_plugins",
"moveit_handeye_calibration::HandEyeTargetBase"));
58 ASSERT_TRUE(
target_->setParameter(
"squares, X", 5));
59 ASSERT_TRUE(
target_->setParameter(
"squares, Y", 7));
60 ASSERT_TRUE(
target_->setParameter(
"marker size (px)", 50));
61 ASSERT_TRUE(
target_->setParameter(
"square size (px)", 80));
62 ASSERT_TRUE(
target_->setParameter(
"margin size (px)", 2));
63 ASSERT_TRUE(
target_->setParameter(
"marker border (bits)", 1));
64 ASSERT_TRUE(
target_->setParameter(
"ArUco dictionary",
"DICT_5X5_250"));
65 ASSERT_TRUE(
target_->setParameter(
"longest board side (m)", 0.1971));
66 ASSERT_TRUE(
target_->setParameter(
"measured marker size (m)", 0.0176));
68 ASSERT_TRUE(
target_->initialize());
72 ROS_ERROR_STREAM(
"Exception while creating handeye target plugin: " << ex.what());
77 "/handeye_calibration_target/test/test_charuco_board_detection.jpg";
79 image_ = cv::imread(image_path, cv::IMREAD_COLOR);
95 pluginlib::UniquePtr<moveit_handeye_calibration::HandEyeTargetBase>
target_;
96 std::unique_ptr<pluginlib::ClassLoader<moveit_handeye_calibration::HandEyeTargetBase> >
target_plugins_loader_;
103 ASSERT_TRUE(resource_ok_);
104 ASSERT_EQ(image_.cols, 640);
105 ASSERT_EQ(image_.rows, 480);
106 ASSERT_TRUE(target_);
112 sensor_msgs::CameraInfoPtr camera_info(
new sensor_msgs::CameraInfo());
113 camera_info->height = 480;
114 camera_info->width = 640;
115 camera_info->header.frame_id =
"camera_color_optical_frame";
116 camera_info->distortion_model =
"plumb_bob";
117 camera_info->D = std::vector<double>{ 0.15405498, -0.24916842, 0.00350791, -0.00110041, 0.0 };
119 boost::array<double, 9>{ 590.6972346, 0.0, 322.33104773, 0.0, 592.84676713, 247.40030325, 0.0, 0.0, 1.0 };
120 camera_info->R = boost::array<double, 9>{ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 };
121 camera_info->P = boost::array<double, 12>{ 590.6972346, 0.0, 322.33104773, 0.0, 0.0, 592.84676713,
122 247.40030325, 0.0, 0.0, 0.0, 1.0, 0.0 };
123 ASSERT_TRUE(target_->setCameraIntrinsicParams(camera_info));
126 cv::Mat target_image;
127 ASSERT_TRUE(target_->createTargetImage(target_image));
131 cv::cvtColor(image_, gray_image, cv::COLOR_RGB2GRAY);
132 ASSERT_TRUE(target_->detectTargetPose(gray_image));
135 geometry_msgs::TransformStamped camera_transform;
137 camera_transform = target_->getTransformStamped(camera_info->header.frame_id);
139 std::cout <<
"Translation:\n"
140 << ret.translation() <<
"\nRotation:\n"
141 << ret.rotation().eulerAngles(0, 1, 2) << std::endl;
142 Eigen::Vector3d
t(0.09752, 0.102848, 0.325596);
143 Eigen::Vector3d
r(2.88409, -0.147996, 1.13757);
146 ASSERT_TRUE(ret.translation().isApprox(t, 0.01));
147 ASSERT_TRUE(ret.rotation().eulerAngles(0, 1, 2).isApprox(r, 0.01));
150 int main(
int argc,
char** argv)
152 testing::InitGoogleTest(&argc, argv);
153 return RUN_ALL_TESTS();