color_histogram.h
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 
00036 #include <ros/ros.h>
00037 #include <nodelet/nodelet.h>
00038 #include <geometry_msgs/PolygonStamped.h>
00039 #include <jsk_recognition_msgs/ColorHistogram.h>
00040 #include <sensor_msgs/image_encodings.h>
00041 #include <cv_bridge/cv_bridge.h>
00042 #include <image_transport/image_transport.h>
00043 #include <image_transport/subscriber_filter.h>
00044 #include <message_filters/subscriber.h>
00045 #include <message_filters/synchronizer.h>
00046 #include <message_filters/sync_policies/exact_time.h>
00047 #include <message_filters/sync_policies/approximate_time.h>
00048 #include <dynamic_reconfigure/server.h>
00049 #include <jsk_perception/ColorHistogramConfig.h>
00050 #include "opencv2/highgui/highgui.hpp"
00051 #include "opencv2/imgproc/imgproc.hpp"
00052 #include <jsk_topic_tools/diagnostic_nodelet.h>
00053 
00054 namespace jsk_perception
00055 {
00056   class ColorHistogram: public jsk_topic_tools::DiagnosticNodelet
00057   {
00058   public:
00059     typedef message_filters::sync_policies::ApproximateTime<
00060     sensor_msgs::Image,
00061     geometry_msgs::PolygonStamped > SyncPolicy;
00062     
00063     typedef message_filters::sync_policies::ApproximateTime<
00064       sensor_msgs::Image,
00065       sensor_msgs::Image> MaskSyncPolicy;
00066     typedef jsk_perception::ColorHistogramConfig Config;
00067     ColorHistogram(): DiagnosticNodelet("ColorHistogram") {}
00068   protected:
00069     boost::shared_ptr<message_filters::Synchronizer<SyncPolicy> > sync_;
00070     boost::shared_ptr<message_filters::Synchronizer<MaskSyncPolicy> > mask_sync_;
00071     boost::shared_ptr<dynamic_reconfigure::Server<Config> > srv_;
00072     image_transport::SubscriberFilter image_sub_;
00073     image_transport::SubscriberFilter image_mask_sub_;
00074     message_filters::Subscriber<geometry_msgs::PolygonStamped> rectangle_sub_;
00075     ros::NodeHandle nh_;
00076     boost::shared_ptr<image_transport::ImageTransport> it_;
00077     ros::Publisher b_hist_pub_, r_hist_pub_, g_hist_pub_,
00078       h_hist_pub_, s_hist_pub_, i_hist_pub_;
00079     ros::Publisher image_pub_;
00080     int b_hist_size_, r_hist_size_, g_hist_size_,
00081       h_hist_size_, s_hist_size_, i_hist_size_;
00082     bool use_mask_;
00083     boost::mutex mutex_;
00084 
00085     void configCallback(Config &new_config, uint32_t level);
00086     virtual void onInit();
00087     virtual void subscribe();
00088     virtual void unsubscribe();
00089     virtual void updateDiagnostic(
00090       diagnostic_updater::DiagnosticStatusWrapper &stat);
00091     virtual void convertHistogramToMsg(
00092       const cv::Mat& hist,
00093       int size,
00094       jsk_recognition_msgs::ColorHistogram& msg);
00095     virtual void processBGR(const cv::Mat& bgr_image,
00096                             const std_msgs::Header& header);
00097     virtual void processHSI(const cv::Mat& bgr_image,
00098                             const std_msgs::Header& header);
00099     virtual void processBGR(const cv::Mat& bgr_image,
00100                             const cv::Mat& mask,
00101                             const std_msgs::Header& header);
00102     virtual void processHSI(const cv::Mat& bgr_image,
00103                             const cv::Mat& mask,
00104                             const std_msgs::Header& header);
00105     virtual void extract(
00106       const sensor_msgs::Image::ConstPtr& image,
00107       const geometry_msgs::PolygonStamped::ConstPtr& rectangle);
00108     virtual void extractMask(
00109       const sensor_msgs::Image::ConstPtr& image,
00110       const sensor_msgs::Image::ConstPtr& mask_image);
00111   private:
00112     
00113   };
00114 }


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Wed Sep 16 2015 04:36:15