resized_publisher.cpp
Go to the documentation of this file.
00001 #include <image_transport_tutorial/resized_publisher.h>
00002 #include <opencv2/imgproc/imgproc.hpp>
00003 #include <cv_bridge/cv_bridge.h>
00004 
00005 void ResizedPublisher::publish(const sensor_msgs::Image& message,
00006                                const PublishFn& publish_fn) const
00007 {
00008   cv::Mat cv_image;
00009   boost::shared_ptr<void const> tracked_object;
00010   try
00011   {
00012     cv_image = cv_bridge::toCvShare(message, tracked_object, message.encoding)->image;
00013   }
00014   catch (cv::Exception &e)
00015   {
00016     ROS_ERROR("Could not convert from '%s' to '%s'.", message.encoding.c_str(), message.encoding.c_str());
00017     return;
00018   }
00019 
00020   // Retrieve subsampling factor from the parameter server
00021   double subsampling_factor;
00022   std::string param_name;
00023   nh().param<double>("resized_image_transport_subsampling_factor", subsampling_factor, 2.0);
00024 
00025   // Rescale image
00026   int new_width = cv_image.cols / subsampling_factor + 0.5;
00027   int new_height = cv_image.rows / subsampling_factor + 0.5;
00028   cv::Mat buffer;
00029   cv::resize(cv_image, buffer, cv::Size(new_width, new_height));
00030 
00031   // Set up ResizedImage and publish
00032   image_transport_tutorial::ResizedImage resized_image;
00033   resized_image.original_height = cv_image.rows;
00034   resized_image.original_width = cv_image.cols;
00035   resized_image.image = *(cv_bridge::CvImage(message.header, "bgr8", cv_image).toImageMsg());
00036   publish_fn(resized_image);
00037 }


image_transport
Author(s): Patrick Mihelich
autogenerated on Thu Jun 6 2019 21:19:55