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(
"markers, X", 4));
59 ASSERT_TRUE(
target_->setParameter(
"markers, Y", 3));
60 ASSERT_TRUE(
target_->setParameter(
"marker size (px)", 200));
61 ASSERT_TRUE(
target_->setParameter(
"marker separation (px)", 20));
62 ASSERT_TRUE(
target_->setParameter(
"marker border (bits)", 1));
63 ASSERT_TRUE(
target_->setParameter(
"ArUco dictionary",
"DICT_4X4_250"));
64 ASSERT_TRUE(
target_->setParameter(
"measured marker size (m)", 0.0256));
65 ASSERT_TRUE(
target_->setParameter(
"measured separation (m)", 0.0066));
67 ASSERT_TRUE(
target_->initialize());
71 ROS_ERROR_STREAM(
"Exception while creating handeye target plugin: " << ex.what());
76 "/handeye_calibration_target/test/test_aruco_marker_detection.png";
78 image_ = cv::imread(image_path, cv::IMREAD_COLOR);
94 pluginlib::UniquePtr<moveit_handeye_calibration::HandEyeTargetBase>
target_;
95 std::unique_ptr<pluginlib::ClassLoader<moveit_handeye_calibration::HandEyeTargetBase> >
target_plugins_loader_;
102 ASSERT_TRUE(resource_ok_);
103 ASSERT_EQ(image_.cols, 640);
104 ASSERT_EQ(image_.rows, 480);
105 ASSERT_TRUE(target_);
111 sensor_msgs::CameraInfoPtr camera_info(
new sensor_msgs::CameraInfo());
112 camera_info->height = 480;
113 camera_info->width = 640;
114 camera_info->header.frame_id =
"camera_color_optical_frame";
115 camera_info->distortion_model =
"plumb_bob";
116 camera_info->D = std::vector<double>{ 0.0, 0.0, 0.0, 0.0, 0.0 };
117 camera_info->K = boost::array<double, 9>{
118 618.6002197265625, 0.0, 321.9837646484375, 0.0, 619.1103515625, 241.1459197998047, 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>{
122 618.6002197265625, 0.0, 321.9837646484375, 0.0, 0.0, 619.1103515625, 241.1459197998047, 0.0, 0.0, 0.0, 1.0, 0.0
124 ASSERT_TRUE(target_->setCameraIntrinsicParams(camera_info));
127 cv::Mat target_image;
128 ASSERT_TRUE(target_->createTargetImage(target_image));
132 cv::cvtColor(image_, gray_image, cv::COLOR_RGB2GRAY);
133 ASSERT_TRUE(target_->detectTargetPose(gray_image));
136 geometry_msgs::TransformStamped camera_transform;
138 camera_transform = target_->getTransformStamped(camera_info->header.frame_id);
140 std::cout <<
"Translation:\n"
141 << ret.translation() <<
"\nRotation:\n"
142 << ret.rotation().eulerAngles(0, 1, 2) << std::endl;
143 #if CV_VERSION_MAJOR == 3 && CV_VERSION_MINOR == 2
145 Eigen::Vector3d
t(0.412949, -0.198895, 11.1761);
146 Eigen::Vector3d
r(0.324172, -2.03144, 2.90114);
148 Eigen::Vector3d
t(0.0148984, 0.0123107, 0.58609);
149 Eigen::Vector3d
r(2.12328, -1.50481, -1.29729);
151 ASSERT_TRUE(ret.translation().isApprox(t, 0.01));
152 ASSERT_TRUE(ret.rotation().eulerAngles(0, 1, 2).isApprox(r, 0.01));
155 int main(
int argc,
char** argv)
157 testing::InitGoogleTest(&argc, argv);
158 return RUN_ALL_TESTS();