8 DiagnosticNodelet::onInit();
26 reconfigure_server_ = boost::make_shared <dynamic_reconfigure::Server<ImageResizerConfig> > (*pnh_);
27 ReconfigureServer::CallbackType
f 35 std::string interpolation_method;
36 pnh_->param<std::string>(
"interpolation", interpolation_method,
"LINEAR");
37 if(interpolation_method ==
"NEAREST"){
39 }
else if(interpolation_method ==
"LINEAR") {
41 }
else if(interpolation_method ==
"AREA") {
43 }
else if(interpolation_method ==
"CUBIC") {
45 }
else if(interpolation_method ==
"LANCZOS4") {
48 ROS_ERROR(
"unknown interpolation method");
53 boost::mutex::scoped_lock lock(
mutex_);
56 cv::Mat mask = cv_ptr->image;
57 int step_x, step_y, ox, oy;
60 int maskwidth = mask.cols;
61 int maskheight = mask.rows;
63 for (
size_t j = 0; j < maskheight; j++) {
64 for (
size_t i = 0; i < maskwidth; i++) {
65 if (mask.at<uchar>(j, i) != 0) {
70 int surface_per = ((double) cnt) / (maskwidth * maskheight) * 100;
72 step_x =
sqrt (surface_per);
81 for (
int i = ox; i <
raw_width_; i += step_x) {
103 void ImageResizer::process(
const sensor_msgs::ImageConstPtr &src_img,
const sensor_msgs::CameraInfoConstPtr &src_info,
104 sensor_msgs::ImagePtr &dst_img, sensor_msgs::CameraInfo &dst_info){
105 int image_width, image_height;
107 image_width = src_info->width;
108 image_height = src_info->height;
111 image_width = src_img->width;
112 image_height = src_img->height;
123 cv::Mat tmpmat(height, width, cv_img->image.type());
128 cv::resize(cv_img->image, tmpmat, cv::Size(width, height), 0, 0,
interpolation_);
129 NODELET_DEBUG(
"mat rows:%d cols:%d", tmpmat.rows, tmpmat.cols);
130 cv_img->image = tmpmat;
132 dst_img = cv_img->toImageMsg();
134 dst_info = *src_info;
135 dst_info.height = height;
136 dst_info.width = width;
137 dst_info.K[0] = dst_info.K[0] * scale_x;
138 dst_info.K[2] = dst_info.K[2] * scale_x;
139 dst_info.K[4] = dst_info.K[4] * scale_y;
140 dst_info.K[5] = dst_info.K[5] * scale_y;
142 dst_info.P[0] = dst_info.P[0] * scale_x;
143 dst_info.P[2] = dst_info.P[2] * scale_x;
144 dst_info.P[3] = dst_info.P[3] * scale_x;
145 dst_info.P[5] = dst_info.P[5] * scale_y;
146 dst_info.P[6] = dst_info.P[6] * scale_y;
void config_cb(ImageResizerConfig &config, uint32_t level)
virtual void unsubscribe()
void initPublishersAndSubscribers()
void process(const sensor_msgs::ImageConstPtr &src_img, const sensor_msgs::CameraInfoConstPtr &src_info, sensor_msgs::ImagePtr &dst_img, sensor_msgs::CameraInfo &dst_info)
virtual void unsubscribe()
boost::shared_ptr< ReconfigureServer > reconfigure_server_
void mask_region_callback(const sensor_msgs::Image::ConstPtr &msg)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
PLUGINLIB_EXPORT_CLASS(ImageResizer, nodelet::Nodelet)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
resized_image_transport::ImageResizer ImageResizer
#define NODELET_INFO(...)
#define NODELET_DEBUG(...)