36 #include <geometry_msgs/PoseStamped.h> 37 #include <opencv2/highgui/highgui.hpp> 38 #include <opencv2/calib3d.hpp> 60 reconfigureServer_->setCallback ( reconfigureFnc_ );
70 for (
int i = 0; i <
config_.checkerboard_rows; i++ ) {
71 for (
int j = 0; j <
config_.checkerboard_columns; j++ ) {
72 object_corners_.push_back ( Point3f (
float ( i *
config_.checkerboard_square_size ), float ( j *
config_.checkerboard_square_size ), 0.f ) );
81 const sensor_msgs::CameraInfoConstPtr& info_msg ) {
83 Size patternsize (
config_.checkerboard_columns,
config_.checkerboard_rows );
87 if(
config_.rotate_camera_image_180) {
95 ROS_ERROR (
"[camera_tf_node] Failed to convert image" );
102 if (
config_.adaptive_thresh ) flags += CV_CALIB_CB_ADAPTIVE_THRESH;
103 if (
config_.normalize_image ) flags += CV_CALIB_CB_NORMALIZE_IMAGE;
104 if (
config_.filter_quads ) flags += CV_CALIB_CB_FILTER_QUADS;
105 if (
config_.fast_check ) flags += CALIB_CB_FAST_CHECK;
108 if ( patternfound ) {
111 int winSize =
config_.subpixelfit_window_size;
112 cornerSubPix (
image_grey_,
image_corners_, Size ( winSize, winSize ), Size ( -1, -1 ), TermCriteria ( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1 ) );
121 if (
config_.input_raw ==
false ) {
123 camera_matrix = projection_matrix ( cv::Rect ( 0,0,3,3 ) );
124 dist_coeff = Mat::zeros ( 1,5,CV_32F );
127 for (
int r = 0; r < 3; r++ )
128 for (
int c = 0; c < 3; c++ )
135 double f = ( fx+fy ) /2.;
142 Vec3d translation_vec;
151 Rodrigues ( rotation_vec, cv::Mat (
extrinsic_matrix_, cv::Rect ( 0, 0, 3, 3 ) ), noArray() );
159 tf::Vector3 t ( translation_vec ( 0 ), translation_vec ( 1 ), translation_vec ( 2 ) );
166 if (
config_.plubish_marker ) {
181 marker.pose.orientation.x = q.x();
182 marker.pose.orientation.y = q.y();
183 marker.pose.orientation.z = q.z();
184 marker.pose.orientation.w = q.w();
185 marker.pose.position.x = t.
x();
186 marker.pose.position.y = t.
y();
187 marker.pose.position.z = t.
z();
190 if (
config_.publish_fiducials ) {
193 for (
size_t i = 0; i < 5; i++)
195 for (
size_t r = 0; r < 3; r++)
196 for (
size_t c = 0; c < 3; c++)
214 geometry_msgs::PoseStamped pose;
215 pose.header = image_msg->header;
216 pose.pose.orientation.x = q.x();
217 pose.pose.orientation.y = q.y();
218 pose.pose.orientation.z = q.z();
219 pose.pose.orientation.w = q.w();
220 pose.pose.position.x = t.
x();
221 pose.pose.position.y = t.
y();
222 pose.pose.position.z = t.
z();
225 if (
config_.show_camera_image ) {
227 double square_size =
config_.checkerboard_square_size;
228 double nr_of_square = std::max (
config_.checkerboard_columns,
config_.checkerboard_rows );
229 double size = square_size * nr_of_square;
231 int font = cv::FONT_HERSHEY_SIMPLEX;
232 double fontScale = 1.0;
233 double thickness = 1.0;
234 double lineType = CV_AA;
235 double lineThickness = 3;
237 cv::Mat_<double> Pi0 =
projection_matrix_ * ( cv::Mat_<double> ( 4,1 ) << 0, 0, 0, 1 );
238 cv::Point2d pi0 ( Pi0 ( 0,0 ) / Pi0 ( 0,2 ), Pi0 ( 0,1 ) / Pi0 ( 0,2 ) );
239 cv::circle (
image_rgb_, pi0, 3, CV_RGB ( 255,255,255 ) );
241 cv::Mat_<double> Pi1 =
projection_matrix_ * ( cv::Mat_<double> ( 4,1 ) << size, 0, 0, 1 );;
242 cv::Point2d pi1 ( Pi1 ( 0,0 ) / Pi1 ( 0,2 ), Pi1 ( 0,1 ) / Pi1 ( 0,2 ) );
243 cv::circle (
image_rgb_, pi1, 3, CV_RGB ( 255,0,0 ) );
244 putText (
image_rgb_,
"X", pi1, font, fontScale, CV_RGB ( 255,0,0 ), thickness, CV_AA );
245 cv::line (
image_rgb_, pi0, pi1, CV_RGB ( 255,0,0 ), lineThickness );
247 cv::Mat_<double> Pi2 =
projection_matrix_ * ( cv::Mat_<double> ( 4,1 ) << 0, size, 0, 1 );
248 cv::Point2d pi2 ( Pi2 ( 0,0 ) / Pi2 ( 0,2 ), Pi2 ( 0,1 ) / Pi2 ( 0,2 ) );
249 cv::circle (
image_rgb_, pi2, 3, CV_RGB ( 0,255,0 ) );
250 putText (
image_rgb_,
"Y", pi2, font, fontScale, CV_RGB ( 0,255,0 ), thickness, CV_AA );
251 cv::line (
image_rgb_, pi0, pi2, CV_RGB ( 0,255,0 ), lineThickness );
253 cv::Mat_<double> Pi3 =
projection_matrix_ * ( cv::Mat_<double> ( 4,1 ) << 0, 0, size, 1 );
254 cv::Point2d pi3 ( Pi3 ( 0,0 ) / Pi3 ( 0,2 ), Pi3 ( 0,1 ) / Pi3 ( 0,2 ) );
255 cv::circle (
image_rgb_, pi3, 3, CV_RGB ( 0,0,255 ) );
256 putText (
image_rgb_,
"Z", pi3, font, fontScale, CV_RGB ( 0,0,255 ) , thickness, CV_AA );
257 cv::line (
image_rgb_, pi0, pi3, CV_RGB ( 0,0,255 ), lineThickness );
261 if (
config_.show_camera_image ) {
265 cv::waitKey (
config_.show_camera_image_waitkey );
270 int main (
int argc,
char** argv ) {
271 ros::init ( argc, argv,
"tuw_checkerboard" );
std::shared_ptr< tf::TransformBroadcaster > tf_broadcaster_
const cv::Matx33d & intrinsicMatrix() const
image_geometry::PinholeCameraModel cam_model_
ros::Publisher pub_fiducials_
void publish(const boost::shared_ptr< M > &message) const
CameraSubscriber subscribeCamera(const std::string &base_topic, uint32_t queue_size, const CameraSubscriber::Callback &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
dynamic_reconfigure::Server< tuw_checkerboard::CheckerboardDetectionConfig > * reconfigureServer_
parameter server stuff
ros::NodeHandle nh_private_
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::vector< cv::Point3f > object_corners_
std::string checkerboard_frame_id_
marker_msgs::MarkerDetection marker_detection_
image_transport::CameraSubscriber sub_cam_
ROSCPP_DECL void spin(Spinner &spinner)
TFSIMD_FORCE_INLINE const tfScalar & x() const
marker_msgs::FiducialDetection fiducial_detection_
TFSIMD_FORCE_INLINE const tfScalar & z() const
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
void callbackCamera(const sensor_msgs::ImageConstPtr &image_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
TFSIMD_FORCE_INLINE const tfScalar & y() const
const std::string & getNamespace() const
std::vector< cv::Point2f > image_corners_
cv::Mat_< double > projection_matrix_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
cv::Mat_< double > extrinsic_matrix_
dynamic_reconfigure::Server< tuw_checkerboard::CheckerboardDetectionConfig >::CallbackType reconfigureFnc_
parameter server stuff
cv::Mat_< double > intrinsic_matrix_
void callbackConfig(tuw_checkerboard::CheckerboardDetectionConfig &_config, uint32_t _level)
callback function on incoming parameter changes
const cv::Matx34d & projectionMatrix() const
const cv::Mat_< double > & distortionCoeffs() const
tuw_checkerboard::CheckerboardDetectionConfig config_
ros::Publisher pub_markers_