20 #include <boost/foreach.hpp> 21 #include <cv_bridge/cv_bridge.h> 25 : it_(nh_), frame_ids_(frame_ids), camera_input_topic_(camera_input_topic), camera_output_topic_(camera_output_topic)
29 void TF_Visualizer::imageCb(
const sensor_msgs::ImageConstPtr& image_msg,
const sensor_msgs::CameraInfoConstPtr& info_msg)
32 cv_bridge::CvImagePtr input_bridge;
34 input_bridge = cv_bridge::toCvCopy(image_msg, sensor_msgs::image_encodings::BGR8);
35 image = input_bridge->image;
37 catch (cv_bridge::Exception& ex){
38 ROS_ERROR(
"[draw_frames] Failed to convert image");
44 BOOST_FOREACH(
const std::string& frame_id,
frame_ids_) {
45 tf::StampedTransform transform;
47 ros::Time acquisition_time = info_msg->header.stamp;
50 acquisition_time, timeout);
52 acquisition_time, transform);
54 catch (tf::TransformException& ex) {
55 ROS_WARN(
"[draw_frames] TF exception:\n%s", ex.what());
59 tf::Point pt = transform.getOrigin();
60 cv::Point3d pt_cv(pt.x(), pt.y(), pt.z());
64 static const int RADIUS = 3;
65 cv::circle(image, uv, RADIUS, CV_RGB(255,0,0), -1);
68 cvGetTextSize(frame_id.c_str(), &
font_, &text_size, &baseline);
69 CvPoint origin = cvPoint(uv.x - text_size.width / 2,
70 uv.y - RADIUS - baseline - 3);
71 cv::putText(image, frame_id.c_str(), origin, cv::FONT_HERSHEY_SIMPLEX, 12, CV_RGB(255,0,0));
74 pub_.publish(input_bridge->toImageMsg());
82 cvInitFont(&
font_, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5);
image_transport::Publisher pub_
std::string resolveName(const std::string &name, bool remap=true) const
std::vector< std::string > frame_ids_
image_geometry::PinholeCameraModel cam_model_
void imageCb(const sensor_msgs::ImageConstPtr &image_msg, const sensor_msgs::CameraInfoConstPtr &info_msg)
std::string camera_input_topic_
image_transport::ImageTransport it_
tf::TransformListener tf_listener_
std::string camera_output_topic_
image_transport::CameraSubscriber sub_
TF_Visualizer(const std::vector< std::string > &frame_ids, std::string camera_input_topic, std::string camera_output_topic)