00001 /********************************************************************* 00002 * 00003 * Copyright (c) 2014, Willow Garage, Inc. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above 00013 * copyright notice, this list of conditions and the following 00014 * disclaimer in the documentation and/or other materials provided 00015 * with the distribution. 00016 * * Neither the name of the Willow Garage nor the names of its 00017 * contributors may be used to endorse or promote products derived 00018 * from this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00030 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 * POSSIBILITY OF SUCH DAMAGE. 00032 00033 * Author: Julius Kammerl (jkammerl@willowgarage.com) 00034 * 00035 */ 00036 00037 #ifndef DEPTHCLOUD_ENCODER_H 00038 #define DEPTHCLOUD_ENCODER_H 00039 00040 #include <iostream> 00041 #include <string> 00042 #include <boost/thread.hpp> 00043 00044 #include <image_transport/image_transport.h> 00045 #include <image_transport/subscriber_filter.h> 00046 00047 #include <sensor_msgs/image_encodings.h> 00048 00049 #include <message_filters/subscriber.h> 00050 #include <message_filters/synchronizer.h> 00051 #include <message_filters/sync_policies/approximate_time.h> 00052 00053 #include "ros/ros.h" 00054 00055 namespace depthcloud 00056 { 00057 00058 class DepthCloudEncoder 00059 { 00060 public: 00061 DepthCloudEncoder(ros::NodeHandle& nh, ros::NodeHandle& pnh); 00062 virtual ~DepthCloudEncoder(); 00063 00064 protected: 00065 00066 void connectCb(); 00067 00068 void subscribe(std::string& depth_topic, std::string& color_topic); 00069 void unsubscribe(); 00070 00071 void depthCB(const sensor_msgs::ImageConstPtr& depth_msg); 00072 00073 void depthColorCB(const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::ImageConstPtr& color_msg); 00074 00075 void depthInterpolation(sensor_msgs::ImageConstPtr depth_msg, 00076 sensor_msgs::ImagePtr depth_int_msg, 00077 sensor_msgs::ImagePtr mask_msg); 00078 00079 void process(const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::ImageConstPtr& color_msg, const std::size_t crop_size); 00080 00081 00082 typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> SyncPolicyDepthColor; 00083 typedef message_filters::Synchronizer<SyncPolicyDepthColor> SynchronizerDepthColor; 00084 00085 ros::NodeHandle& nh_; 00086 ros::NodeHandle& pnh_; 00087 00088 // ROS stuff 00089 boost::shared_ptr<image_transport::SubscriberFilter > depth_sub_; 00090 boost::shared_ptr<image_transport::SubscriberFilter > color_sub_; 00091 00092 boost::shared_ptr<SynchronizerDepthColor> sync_depth_color_; 00093 00094 boost::mutex connect_mutex_; 00095 00096 image_transport::ImageTransport pub_it_; 00097 image_transport::Publisher pub_; 00098 00099 std::size_t crop_size_; 00100 00101 std::string depthmap_topic_; 00102 std::string rgb_image_topic_; 00103 00104 }; 00105 00106 } 00107 00108 #endif 00109