label_array_to_mask_image.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2018, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
36 #include <algorithm>
37 #include <jsk_topic_tools/log_utils.h>
38 #include <sensor_msgs/Image.h>
39 #include <cv_bridge/cv_bridge.h>
41 #include <boost/assign.hpp>
42 
43 namespace jsk_perception
44 {
45 
47  {
48  DiagnosticNodelet::onInit();
49  pub_ = advertise<sensor_msgs::Image>(*pnh_, "output", 1);
50  pnh_->param("label_values", label_array_value_, std::vector<int>{});
51  onInitPostProcess();
52  }
53 
55  {
56  sub_ = pnh_->subscribe("input", 1,
58  this);
59  ros::V_string names = boost::assign::list_of("~input");
60  jsk_topic_tools::warnNoRemap(names);
61  }
62 
64  {
65  sub_.shutdown();
66  }
67 
69  const sensor_msgs::Image::ConstPtr& label_msg)
70  {
73 
74  cv::Mat mask_image = cv::Mat::zeros(label_msg->height,
75  label_msg->width,
76  CV_8UC1);
77  for (size_t j = 0; j < label_img_ptr->image.rows; j++)
78  {
79  for (size_t i = 0; i < label_img_ptr->image.cols; i++)
80  {
81  int label = label_img_ptr->image.at<int>(j, i);
82  std::vector<int>::iterator it = std::find(
84  if (it != label_array_value_.end()) {
85  mask_image.at<uchar>(j, i) = 255;
86  }
87  }
88  }
90  label_msg->header,
92  mask_image).toImageMsg());
93  }
94 
95 } // namespace jsk_perception
96 
jsk_perception::LabelArrayToMaskImage::onInit
virtual void onInit()
Definition: label_array_to_mask_image.cpp:78
image_encodings.h
jsk_perception::LabelArrayToMaskImage::sub_
ros::Subscriber sub_
Definition: label_array_to_mask_image.h:124
boost::shared_ptr< CvImage >
i
int i
cv_bridge::CvImage::toImageMsg
sensor_msgs::ImagePtr toImageMsg() const
label
label
ros::Subscriber::shutdown
void shutdown()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
class_list_macros.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_perception::LabelArrayToMaskImage, nodelet::Nodelet)
jsk_perception
Definition: add_mask_image.h:48
jsk_perception::LabelArrayToMaskImage::convert
virtual void convert(const sensor_msgs::Image::ConstPtr &label_msg)
Definition: label_array_to_mask_image.cpp:100
jsk_perception::LabelArrayToMaskImage::unsubscribe
virtual void unsubscribe()
Definition: label_array_to_mask_image.cpp:95
cv_bridge::toCvCopy
CvImagePtr toCvCopy(const sensor_msgs::CompressedImage &source, const std::string &encoding=std::string())
jsk_perception::LabelArrayToMaskImage::label_array_value_
std::vector< int > label_array_value_
Definition: label_array_to_mask_image.h:126
label_array_to_mask_image.h
nodelet::Nodelet
jsk_perception::LabelArrayToMaskImage::pub_
ros::Publisher pub_
Definition: label_array_to_mask_image.h:125
sensor_msgs::image_encodings::TYPE_32SC1
const std::string TYPE_32SC1
jsk_perception::LabelArrayToMaskImage
Definition: label_array_to_mask_image.h:79
sensor_msgs::image_encodings::MONO8
const std::string MONO8
cv_bridge.h
cv_bridge::CvImage
ros::V_string
std::vector< std::string > V_string
jsk_perception::LabelArrayToMaskImage::subscribe
virtual void subscribe()
Definition: label_array_to_mask_image.cpp:86


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17