mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-07 02:07:45 +08:00
131 lines
4.9 KiB
C++
131 lines
4.9 KiB
C++
/*
|
|
Copyright (c) 2010-2022, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
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 Universite de Sherbrooke 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 HOLDER 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 <rtabmap_util/rgbd_split.hpp>
|
|
|
|
#ifdef PRE_ROS_IRON
|
|
#include <cv_bridge/cv_bridge.h>
|
|
#else
|
|
#include <cv_bridge/cv_bridge.hpp>
|
|
#endif
|
|
|
|
namespace rtabmap_util
|
|
{
|
|
|
|
RGBDSplit::RGBDSplit(const rclcpp::NodeOptions & options) :
|
|
Node("rgbd_split", options)
|
|
{
|
|
int qos = RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT;
|
|
qos = this->declare_parameter("qos", qos);
|
|
|
|
RCLCPP_INFO(this->get_logger(), "%s: qos = %d", get_name(), qos);
|
|
|
|
rgbdImageSub_ = create_subscription<rtabmap_msgs::msg::RGBDImage>("rgbd_image", rclcpp::QoS(5).reliability((rmw_qos_reliability_policy_t)qos), std::bind(&RGBDSplit::callback, this, std::placeholders::_1));
|
|
|
|
rgbPub_ = image_transport::create_publisher(this, std::string(rgbdImageSub_->get_topic_name()) + "/rgb/image", rclcpp::QoS(1).reliability((rmw_qos_reliability_policy_t)qos).get_rmw_qos_profile());
|
|
depthPub_ = image_transport::create_publisher(this, std::string(rgbdImageSub_->get_topic_name()) + "/depth/image", rclcpp::QoS(1).reliability((rmw_qos_reliability_policy_t)qos).get_rmw_qos_profile());
|
|
rgbInfoPub_ = this->create_publisher<sensor_msgs::msg::CameraInfo>(std::string(rgbdImageSub_->get_topic_name()) + "/rgb/camera_info", 1);
|
|
depthInfoPub_ = this->create_publisher<sensor_msgs::msg::CameraInfo>(std::string(rgbdImageSub_->get_topic_name()) + "/depth/camera_info", 1);
|
|
}
|
|
|
|
|
|
void RGBDSplit::callback(const rtabmap_msgs::msg::RGBDImage::SharedPtr input) const
|
|
{
|
|
if(rgbPub_.getNumSubscribers())
|
|
{
|
|
sensor_msgs::msg::Image outputImage;
|
|
sensor_msgs::msg::CameraInfo outputCameraInfo;
|
|
outputImage.header = outputCameraInfo.header = input->header;
|
|
outputCameraInfo = input->rgb_camera_info;
|
|
|
|
if(!input->rgb.data.empty())
|
|
{
|
|
// already raw, just copy pointer
|
|
outputImage = input->rgb;
|
|
}
|
|
else if(!input->rgb_compressed.data.empty())
|
|
{
|
|
#ifdef CV_BRIDGE_HYDRO
|
|
ROS_ERROR("Unsupported compressed image copy, please upgrade at least to ROS Indigo to use this.");
|
|
#else
|
|
cv_bridge::toCvCopy(input->rgb_compressed)->toImageMsg(outputImage);
|
|
#endif
|
|
}
|
|
rgbPub_.publish(outputImage);
|
|
rgbInfoPub_->publish(outputCameraInfo);
|
|
}
|
|
|
|
if(depthPub_.getNumSubscribers())
|
|
{
|
|
sensor_msgs::msg::Image outputImage;
|
|
sensor_msgs::msg::CameraInfo outputCameraInfo;
|
|
outputCameraInfo = input->depth_camera_info;
|
|
|
|
if(!input->depth.data.empty())
|
|
{
|
|
// already raw, just copy pointer
|
|
outputImage = input->depth;
|
|
}
|
|
else if(!input->depth_compressed.data.empty())
|
|
{
|
|
#ifdef CV_BRIDGE_HYDRO
|
|
ROS_ERROR("Unsupported compressed image copy, please upgrade at least to ROS Indigo to use this.");
|
|
#else
|
|
cv_bridge::toCvCopy(input->depth_compressed)->toImageMsg(outputImage);
|
|
#endif
|
|
}
|
|
if(outputCameraInfo.header.frame_id.empty()) {
|
|
if(outputImage.header.frame_id.empty()) {
|
|
outputCameraInfo.header = input->header;
|
|
}
|
|
else {
|
|
outputCameraInfo.header = outputImage.header;
|
|
}
|
|
}
|
|
if(outputImage.header.frame_id.empty()) {
|
|
if(outputCameraInfo.header.frame_id.empty()) {
|
|
outputImage.header = input->header;
|
|
}
|
|
else {
|
|
outputImage.header = outputCameraInfo.header;
|
|
}
|
|
}
|
|
depthPub_.publish(outputImage);
|
|
depthInfoPub_->publish(outputCameraInfo);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#include "rclcpp_components/register_node_macro.hpp"
|
|
|
|
// Register the component with class_loader.
|
|
// This acts as a sort of entry point, allowing the component to be discoverable when its library
|
|
// is being loaded into a running process.
|
|
RCLCPP_COMPONENTS_REGISTER_NODE(rtabmap_util::RGBDSplit)
|
|
|