diff --git a/doc/jsk_perception/nodes/images/invert_mask_image.jpg b/doc/jsk_perception/nodes/images/invert_mask_image.jpg new file mode 100644 index 0000000000..041079262a Binary files /dev/null and b/doc/jsk_perception/nodes/images/invert_mask_image.jpg differ diff --git a/doc/jsk_perception/nodes/invert_mask_image.md b/doc/jsk_perception/nodes/invert_mask_image.md new file mode 100644 index 0000000000..30be57a1a0 --- /dev/null +++ b/doc/jsk_perception/nodes/invert_mask_image.md @@ -0,0 +1,29 @@ +# InvertMaskImage + +![](images/invert_mask_image.jpg) + +Inverts the input mask image. + +## Subscribing Topic + +* `~input` (`sensor_msgs/Image`) + + Input mask image. + +## Publishing Topic + +* `~output` (`sensor_msgs/Image`) + + Inverted mask image. + +## Parameters + +* `~queue_size` (Int, default: `1`) + + How many messages you allow about the subscriber to keep in the queue. + +## Sample + +```bash +roslaunch jsk_perception sample_invert_mask_image.launch +``` diff --git a/jsk_perception/CMakeLists.txt b/jsk_perception/CMakeLists.txt index 07b572b0c2..c79bcdee74 100644 --- a/jsk_perception/CMakeLists.txt +++ b/jsk_perception/CMakeLists.txt @@ -260,6 +260,7 @@ jsk_add_nodelet(src/overlay_image_color_on_mono.cpp "jsk_perception/OverlayImage jsk_add_nodelet(src/grid_label.cpp "jsk_perception/GridLabel" "grid_label") jsk_add_nodelet(src/color_histogram_label_match.cpp "jsk_perception/ColorHistogramLabelMatch" "color_histogram_label_match") jsk_add_nodelet(src/apply_mask_image.cpp "jsk_perception/ApplyMaskImage" "apply_mask_image") +jsk_add_nodelet(src/invert_mask_image.cpp "jsk_perception/InvertMaskImage" "invert_mask_image") jsk_add_nodelet(src/unapply_mask_image.cpp "jsk_perception/UnapplyMaskImage" "unapply_mask_image") jsk_add_nodelet(src/single_channel_histogram.cpp "jsk_perception/SingleChannelHistogram" "single_channel_histogram") jsk_add_nodelet(src/blob_detector.cpp "jsk_perception/BlobDetector" "blob_detector") diff --git a/jsk_perception/include/jsk_perception/invert_mask_image.h b/jsk_perception/include/jsk_perception/invert_mask_image.h new file mode 100644 index 0000000000..6d6ce4b03f --- /dev/null +++ b/jsk_perception/include/jsk_perception/invert_mask_image.h @@ -0,0 +1,66 @@ +// -*- mode: c++ -*- +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2022, JSK Lab + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the JSK Lab nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + + +#ifndef JSK_PERCEPTION_INVERT_MASK_IMAGE_H_ +#define JSK_PERCEPTION_INVERT_MASK_IMAGE_H_ + +#include +#include +#include + + +namespace jsk_perception +{ + class InvertMaskImage: public jsk_topic_tools::DiagnosticNodelet + { + public: + InvertMaskImage(): DiagnosticNodelet("InvertMaskImage") {} + virtual ~InvertMaskImage(); + protected: + + virtual void onInit(); + virtual void subscribe(); + virtual void unsubscribe(); + virtual void invert(const sensor_msgs::Image::ConstPtr& mask_msg); + + boost::mutex mutex_; + ros::Subscriber sub_mask_; + ros::Publisher pub_mask_; + private: + }; +} + +#endif diff --git a/jsk_perception/plugins/nodelet/libjsk_perception.xml b/jsk_perception/plugins/nodelet/libjsk_perception.xml index 44d61af4f0..35828883fc 100644 --- a/jsk_perception/plugins/nodelet/libjsk_perception.xml +++ b/jsk_perception/plugins/nodelet/libjsk_perception.xml @@ -143,6 +143,9 @@ + + diff --git a/jsk_perception/sample/sample_invert_mask_image.launch b/jsk_perception/sample/sample_invert_mask_image.launch new file mode 100644 index 0000000000..d7c338f962 --- /dev/null +++ b/jsk_perception/sample/sample_invert_mask_image.launch @@ -0,0 +1,81 @@ + + + + + + + + + + + file_name: $(find jsk_perception)/sample/kiva_pod_image_color.jpg + encoding: bgr8 + publish_info: false + + + + + + + file_name: $(find jsk_perception)/sample/kiva_pod_mask.jpg + encoding: mono8 + publish_info: false + + + + + + + + + + + + + + approximate_sync: true + + + + + + + + approximate_sync: true + + + + + + + + + + + + + + + + + + + diff --git a/jsk_perception/src/invert_mask_image.cpp b/jsk_perception/src/invert_mask_image.cpp new file mode 100644 index 0000000000..3fca1bdd69 --- /dev/null +++ b/jsk_perception/src/invert_mask_image.cpp @@ -0,0 +1,88 @@ +// -*- mode: c++ -*- +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2022, JSK Lab + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the JSK Lab nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +#include "jsk_perception/invert_mask_image.h" +#include +#include +#include +#include + + +namespace jsk_perception +{ + void InvertMaskImage::onInit() + { + DiagnosticNodelet::onInit(); + pub_mask_ = advertise(*pnh_, "output", 1); + onInitPostProcess(); + } + + InvertMaskImage::~InvertMaskImage() { + } + + void InvertMaskImage::subscribe() + { + int queue_size; + pnh_->param("queue_size", queue_size, 1); + sub_mask_ = pnh_->subscribe("input", queue_size, &InvertMaskImage::invert, this); + ros::V_string names = boost::assign::list_of("~input"); + jsk_topic_tools::warnNoRemap(names); + } + + void InvertMaskImage::unsubscribe() + { + sub_mask_.shutdown(); + } + + void InvertMaskImage::invert(const sensor_msgs::Image::ConstPtr& mask_msg) + { + vital_checker_->poke(); + cv::Mat mask; + try { + mask = cv_bridge::toCvShare(mask_msg, "mono8")->image; + } catch(std::exception &e) { + ROS_ERROR("cv_bridge exception: %s", e.what()); + return; + } + cv::bitwise_not(mask, mask); + pub_mask_.publish(cv_bridge::CvImage( + mask_msg->header, + "mono8", + mask).toImageMsg()); + } +} + +#include +PLUGINLIB_EXPORT_CLASS (jsk_perception::InvertMaskImage, nodelet::Nodelet); diff --git a/jsk_perception/test/invert_mask_image.test b/jsk_perception/test/invert_mask_image.test new file mode 100644 index 0000000000..73dff168cc --- /dev/null +++ b/jsk_perception/test/invert_mask_image.test @@ -0,0 +1,19 @@ + + + + + + + + + topic_0: /invert_mask_image/output + timeout_0: 30 + check_after_kill_node: true + node_names: [invert_mask_image,] + + + +