32 #include <pcl/point_cloud.h> 33 #include <pcl/point_types.h> 38 #include <sensor_msgs/PointCloud2.h> 39 #include <sensor_msgs/Image.h> 41 #include <sensor_msgs/CameraInfo.h> 43 #include <stereo_msgs/DisparityImage.h> 56 #include <opencv2/highgui/highgui.hpp> 112 bool approxSync =
true;
114 pnh.
param(
"approx_sync", approxSync, approxSync);
115 pnh.
param(
"queue_size", queueSize, queueSize);
125 pnh.
param(
"roi_ratios", roiStr, roiStr);
131 std::list<std::string> strValues =
uSplit(roiStr,
' ');
132 if(strValues.size() != 4)
134 ROS_ERROR(
"The number of values must be 4 (\"roi_ratios\"=\"%s\")", roiStr.c_str());
138 std::vector<float> tmpValues(4);
140 for(std::list<std::string>::iterator jter = strValues.begin(); jter!=strValues.end(); ++jter)
146 if(tmpValues[0] >= 0 && tmpValues[0] < 1 && tmpValues[0] < 1.0
f-tmpValues[1] &&
147 tmpValues[1] >= 0 && tmpValues[1] < 1 && tmpValues[1] < 1.0
f-tmpValues[0] &&
148 tmpValues[2] >= 0 && tmpValues[2] < 1 && tmpValues[2] < 1.0
f-tmpValues[3] &&
149 tmpValues[3] >= 0 && tmpValues[3] < 1 && tmpValues[3] < 1.0
f-tmpValues[2])
155 ROS_ERROR(
"The roi ratios are not valid (\"roi_ratios\"=\"%s\")", roiStr.c_str());
162 for(rtabmap::ParametersMap::iterator iter=stereoBMParameters_.begin(); iter!=stereoBMParameters_.end(); ++iter)
170 NODELET_INFO(
"point_cloud_xyzrgb: Setting parameter \"%s\"=\"%s\"", iter->first.c_str(), vStr.c_str());
173 else if(pnh.
getParam(iter->first, vBool))
175 NODELET_INFO(
"point_cloud_xyzrgb: Setting parameter \"%s\"=\"%s\"", iter->first.c_str(),
uBool2Str(vBool).c_str());
178 else if(pnh.
getParam(iter->first, vDouble))
180 NODELET_INFO(
"point_cloud_xyzrgb: Setting parameter \"%s\"=\"%s\"", iter->first.c_str(),
uNumber2Str(vDouble).c_str());
183 else if(pnh.
getParam(iter->first, vInt))
185 NODELET_INFO(
"point_cloud_xyzrgb: Setting parameter \"%s\"=\"%s\"", iter->first.c_str(),
uNumber2Str(vInt).c_str());
190 NODELET_INFO(
"Approximate time sync = %s", approxSync?
"true":
"false");
251 const sensor_msgs::ImageConstPtr& image,
252 const sensor_msgs::ImageConstPtr& imageDepth,
253 const sensor_msgs::CameraInfoConstPtr& cameraInfo)
267 NODELET_ERROR(
"Input type must be image=mono8,mono16,rgb8,bgr8 and image_depth=32FC1,16UC1,mono16");
295 ROS_ASSERT(imageDepthPtr->image.cols == imagePtr->image.cols);
296 ROS_ASSERT(imageDepthPtr->image.rows == imagePtr->image.rows);
298 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pclCloud;
304 model.
cx()-
roiRatios_[0]*double(imageDepthPtr->image.cols),
305 model.
cy()-
roiRatios_[2]*double(imageDepthPtr->image.rows));
306 pcl::IndicesPtr indices(
new std::vector<int>);
308 cv::Mat(imagePtr->image, roi),
309 cv::Mat(imageDepthPtr->image, roi),
324 const sensor_msgs::ImageConstPtr& image,
325 const stereo_msgs::DisparityImageConstPtr& imageDisparity,
326 const sensor_msgs::CameraInfoConstPtr& cameraInfo)
346 NODELET_ERROR(
"Input type must be disparity=32FC1 or 16SC1");
353 disparity = cv::Mat(imageDisparity->image.height, imageDisparity->image.width, CV_32FC1, const_cast<uchar*>(imageDisparity->image.data.data()));
357 disparity = cv::Mat(imageDisparity->image.height, imageDisparity->image.width, CV_16SC1, const_cast<uchar*>(imageDisparity->image.data.data()));
366 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pclCloud;
369 pcl::IndicesPtr indices(
new std::vector<int>);
371 cv::Mat(imagePtr->image, roi),
372 cv::Mat(disparity, roi),
386 const sensor_msgs::ImageConstPtr& imageRight,
387 const sensor_msgs::CameraInfoConstPtr& camInfoLeft,
388 const sensor_msgs::CameraInfoConstPtr& camInfoRight)
399 NODELET_ERROR(
"Input type must be image=mono8,mono16,rgb8,bgr8 (enc=%s)", imageLeft->encoding.c_str());
421 ROS_WARN(
"\"roi_ratios\" set but ignored for stereo images.");
424 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pclCloud;
425 pcl::IndicesPtr indices(
new std::vector<int>);
428 ptrRightImage->image,
449 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pclCloud;
450 pcl::IndicesPtr indices(
new std::vector<int>);
468 void processAndPublish(pcl::PointCloud<pcl::PointXYZRGB>::Ptr & pclCloud, pcl::IndicesPtr & indices,
const std_msgs::Header & header)
478 if(pclCloud->is_dense)
486 pcl::PointCloud<pcl::PointXYZRGB>::Ptr tmp(
new pcl::PointCloud<pcl::PointXYZRGB>);
487 pcl::copyPointCloud(*pclCloud, *indices, *tmp);
491 sensor_msgs::PointCloud2 rosCloud;
496 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr pclCloudNormal(
new pcl::PointCloud<pcl::PointXYZRGBNormal>);
497 pcl::concatenateFields(*pclCloud, *normals, *pclCloudNormal);
512 rosCloud.header.stamp = header.stamp;
513 rosCloud.header.frame_id = header.frame_id;
ros::Subscriber rgbdImageSub_
CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
const std::string BAYER_GRBG8
void processAndPublish(pcl::PointCloud< pcl::PointXYZRGB >::Ptr &pclCloud, pcl::IndicesPtr &indices, const std_msgs::Header &header)
void disparityCallback(const sensor_msgs::ImageConstPtr &image, const stereo_msgs::DisparityImageConstPtr &imageDisparity, const sensor_msgs::CameraInfoConstPtr &cameraInfo)
#define NODELET_ERROR(...)
rtabmap::StereoCameraModel stereoCameraModelFromROS(const sensor_msgs::CameraInfo &leftCamInfo, const sensor_msgs::CameraInfo &rightCamInfo, const rtabmap::Transform &localTransform=rtabmap::Transform::getIdentity())
void publish(const boost::shared_ptr< M > &message) const
std::vector< float > roiRatios_
rtabmap::SensorData rgbdImageFromROS(const rtabmap_ros::RGBDImageConstPtr &image)
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoSub_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string resolveName(const std::string &name, bool remap=true) const
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP removeNaNFromPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud)
void stereoCallback(const sensor_msgs::ImageConstPtr &imageLeft, const sensor_msgs::ImageConstPtr &imageRight, const sensor_msgs::CameraInfoConstPtr &camInfoLeft, const sensor_msgs::CameraInfoConstPtr &camInfoRight)
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo > MyApproxSyncDepthPolicy
std::map< std::string, std::string > ParametersMap
const std::string TYPE_8UC1
std::string uBool2Str(bool boolean)
image_transport::SubscriberFilter imageRight_
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
ros::NodeHandle & getPrivateNodeHandle() const
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromDepthRGB(const cv::Mat &imageRgb, const cv::Mat &imageDepth, const CameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo > MyApproxSyncStereoPolicy
message_filters::Synchronizer< MyApproxSyncStereoPolicy > * approxSyncStereo_
message_filters::Synchronizer< MyExactSyncStereoPolicy > * exactSyncStereo_
std::string uNumber2Str(unsigned int number)
message_filters::Synchronizer< MyApproxSyncDepthPolicy > * approxSyncDepth_
image_transport::SubscriberFilter imageDepthSub_
message_filters::sync_policies::ExactTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo > MyExactSyncDepthPolicy
void depthCallback(const sensor_msgs::ImageConstPtr &image, const sensor_msgs::ImageConstPtr &imageDepth, const sensor_msgs::CameraInfoConstPtr &cameraInfo)
message_filters::Synchronizer< MyExactSyncDepthPolicy > * exactSyncDepth_
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
message_filters::sync_policies::ExactTime< sensor_msgs::Image, stereo_msgs::DisparityImage, sensor_msgs::CameraInfo > MyExactSyncDisparityPolicy
const std::string TYPE_32FC1
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudRGBFromSensorData(const SensorData &sensorData, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap &stereoParameters=ParametersMap(), const std::vector< float > &roiRatios=std::vector< float >())
rtabmap::CameraModel cameraModelFromROS(const sensor_msgs::CameraInfo &camInfo, const rtabmap::Transform &localTransform=rtabmap::Transform::getIdentity())
cv::Rect RTABMAP_EXP computeRoi(const cv::Mat &image, const std::string &roiRatios)
image_transport::SubscriberFilter imageSub_
const std::string TYPE_16UC1
cv::Mat RTABMAP_EXP computeNormals(const cv::Mat &laserScan, int searchK, float searchRadius)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::NodeHandle & getNodeHandle() const
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoRight_
void subscribe(ImageTransport &it, const std::string &base_topic, uint32_t queue_size, const TransportHints &transport_hints=TransportHints())
double noiseFilterRadius_
pcl::IndicesPtr RTABMAP_EXP radiusFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float radiusSearch, int minNeighborsInRadius)
static const ParametersMap & getDefaultParameters()
#define NODELET_INFO(...)
virtual ~PointCloudXYZRGB()
uint32_t getNumSubscribers() const
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
message_filters::Synchronizer< MyApproxSyncDisparityPolicy > * approxSyncDisparity_
bool getParam(const std::string &key, std::string &s) const
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
int noiseFilterMinNeighbors_
message_filters::Subscriber< stereo_msgs::DisparityImage > imageDisparitySub_
float uStr2Float(const std::string &str)
PLUGINLIB_EXPORT_CLASS(rtabmap_ros::CoreWrapper, nodelet::Nodelet)
message_filters::sync_policies::ApproximateTime< sensor_msgs::Image, stereo_msgs::DisparityImage, sensor_msgs::CameraInfo > MyApproxSyncDisparityPolicy
pcl::PointCloud< pcl::PointNormal >::Ptr RTABMAP_EXP removeNaNNormalsFromPointCloud(const pcl::PointCloud< pcl::PointNormal >::Ptr &cloud)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromStereoImages(const cv::Mat &imageLeft, const cv::Mat &imageRight, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap ¶meters=ParametersMap())
message_filters::sync_policies::ExactTime< sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo > MyExactSyncStereoPolicy
message_filters::Subscriber< sensor_msgs::CameraInfo > cameraInfoLeft_
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromDisparityRGB(const cv::Mat &imageRgb, const cv::Mat &imageDisparity, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
rtabmap::ParametersMap stereoBMParameters_
#define NODELET_DEBUG(...)
void rgbdImageCallback(const rtabmap_ros::RGBDImageConstPtr &image)
image_transport::SubscriberFilter imageLeft_
message_filters::Synchronizer< MyExactSyncDisparityPolicy > * exactSyncDisparity_
const std::string TYPE_16SC1