42 #include <opencv2/opencv.hpp>
43 #include <sensor_msgs/CameraInfo.h>
47 #include <geometry_msgs/TransformStamped.h>
48 #include <opencv2/core/eigen.hpp>
58 class HandEyeTargetBase
65 const std::string
name_;
80 ROS_ERROR(
"Integer default value specified for non-integer parameter %s",
name.c_str());
89 ROS_ERROR(
"Float default value specified for non-float parameter %s",
name.c_str());
98 ROS_ERROR(
"Float default value specified for non-float parameter %s",
name.c_str());
102 size_t default_option = 0)
108 ROS_ERROR(
"Invalid default option for enum parameter %s",
name.c_str());
112 const std::string
LOGNAME =
"handeye_target_base";
118 {
"rational_polynomial", 8 } };
154 virtual geometry_msgs::TransformStamped
getTransformStamped(
const std::string& frame_id)
const
156 geometry_msgs::TransformStamped transform_stamped;
158 transform_stamped.header.frame_id = frame_id;
159 transform_stamped.child_frame_id =
"handeye_target";
164 return transform_stamped;
170 cv::Mat cv_rotation_matrix;
171 cv::Rodrigues(input_rvect, cv_rotation_matrix);
173 Eigen::Matrix3d eigen_rotation_matrix;
174 cv::cv2eigen(cv_rotation_matrix, eigen_rotation_matrix);
175 return tf2::toMsg(Eigen::Quaterniond(eigen_rotation_matrix));
181 Eigen::Vector3d eigen_tvect;
182 cv::cv2eigen(input_tvect, eigen_tvect);
183 geometry_msgs::Vector3 msg_tvect;
189 void drawAxis(cv::InputOutputArray _image, cv::InputArray _cameraMatrix, cv::InputArray _distCoeffs,
190 cv::InputArray _rvec, cv::InputArray _tvec,
float length)
const
192 CV_Assert(_image.getMat().total() != 0 && (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
196 std::vector<cv::Point3f> axis_points;
197 axis_points.push_back(cv::Point3f(0, 0, 0));
198 axis_points.push_back(cv::Point3f(
length, 0, 0));
199 axis_points.push_back(cv::Point3f(0,
length, 0));
200 axis_points.push_back(cv::Point3f(0, 0, length));
201 std::vector<cv::Point2f> image_points;
202 cv::projectPoints(axis_points, _rvec, _tvec, _cameraMatrix, _distCoeffs, image_points);
205 cv::line(_image, image_points[0], image_points[1], cv::Scalar(255, 0, 0), 3);
206 cv::line(_image, image_points[0], image_points[2], cv::Scalar(0, 255, 0), 3);
207 cv::line(_image, image_points[0], image_points[3], cv::Scalar(0, 0, 255), 3);
225 ROS_ERROR_NAMED(
LOGNAME,
"Invalid camera matrix dimension, current is %ld, required is %zu.", msg->K.size(),
236 const size_t camera_distortion_vector_dimension =
239 if (msg->D.size() != camera_distortion_vector_dimension)
242 msg->D.size(), camera_distortion_vector_dimension);
246 std::lock_guard<std::mutex> base_lock(
base_mutex_);
259 for (
size_t i = 0; i < camera_distortion_vector_dimension; i++)
296 param.value_.i = value;
307 virtual bool setParameter(std::string name,
float value)
324 virtual bool setParameter(std::string name,
double value)
330 param.value_.f = value;
341 virtual bool setParameter(std::string name, std::string value)
347 auto it = std::find(
param.enum_values_.begin(),
param.enum_values_.end(), value);
348 if (it !=
param.enum_values_.end())
350 param.value_.e = std::distance(
param.enum_values_.begin(), it);
362 virtual bool getParameter(std::string name,
int& value)
const
368 value =
param.value_.i;
379 virtual bool getParameter(std::string name,
float& value)
const
385 value =
param.value_.f;
396 virtual bool getParameter(std::string name,
double& value)
const
402 value =
param.value_.f;
413 virtual bool getParameter(std::string name, std::string& value)
const