depth_segmentation_node.cpp
depth_image_sub_topic
rgb_image_sub_topic
depth_camera_info_sub_topic
rgb_camera_info_topic
instance_segmentation_sub
制定同步话题的策略:ImageSegmentationSyncPolicy、cameraInfoSyncPolicy
发布话题:
object_segment
segmented_scene
2.回调函数
cameraInfoCallback(初始化depth_camera_,rgb_camera_,depth_segmenter_,camera_tracker)初始化一次之后就不回执行了
imageSegmentationCallback
(1)将接收的语义分割的消息Result从ros消息转换到自定义的消息类型semanticInstanceSegmentationFromRosMsg(Result–>SemanticInstanceSegmentation)
(2)将接收的rgb消息转为opencv格式
cv_bridge::CvImagePtr cv_rgb_image(new cv_bridge::CvImage); //typedef boost::shared_ptr CvImagePtr为智能指针
//CvImagePtr toCvCopy(const sensor_msgs::Image& source,const std::string& encoding = std::string());
cv_rgb_image = cv_bridge::toCvCopy(rgb_msg, rgb_msg->encoding);
(3)预处理深度图preprocess
(4)计算边图computeEdgeMap
(5)集合分割的段标签,找到最大的overlap,并分配实例标签
1.定义消息同步机制
typedef message_filters::sync_policies::ApproximateTime<
sensor_msgs::Image, sensor_msgs::Image, mask_rcnn_ros::Result>
ImageSegmentationSyncPolicy;
typedef message_filters::sync_policies::ApproximateTime<
sensor_msgs::CameraInfo, sensor_msgs::CameraInfo>
CameraInfoSyncPolicy;
2.定义类成员变量指针
image_transport::SubscriberFilter* depth_image_sub_;
image_transport::SubscriberFilter* rgb_image_sub_;
message_filters::Subscriber<sensor_msgs::CameraInfo>* depth_info_sub_;
message_filters::Subscriber<sensor_msgs::CameraInfo>* rgb_info_sub_;
message_filters::Subscriber<mask_rcnn_ros::Result>* instance_segmentation_sub_;
message_filters::Synchronizer<ImageSyncPolicy>* image_sync_policy_;
message_filters::Synchronizer<CameraInfoSyncPolicy>* camera_info_sync_policy_;
message_filters::Synchronizer<ImageSegmentationSyncPolicy>* image_segmentation_sync_policy_;
3.用new开辟空间,订阅需要同步的话题
depth_image_sub_ = new image_transport::SubscriberFilter(image_transport_, depth_image_topic_, 1);
rgb_image_sub_ = new image_transport::SubscriberFilter(image_transport_, rgb_image_topic_, 1);
depth_info_sub_ = new message_filters::Subscriber<sensor_msgs::CameraInfo>(node_handle_, depth_camera_info_topic_, 1);
rgb_info_sub_ = new message_filters::Subscriber<sensor_msgs::CameraInfo>(node_handle_, rgb_camera_info_topic_, 1);
instance_segmentation_sub_ =new message_filters::Subscriber<mask_rcnn_ros::Result>(node_handle_, semantic_instance_segmentation_topic_, 1);
//message_filter中
//template<class Policy>
//class Synchronizer类对象
image_segmentation_sync_policy_ =new message_filters::Synchronizer<ImageSegmentationSyncPolicy>(ImageSegmentationSyncPolicy(kQueueSize), *depth_image_sub_,*rgb_image_sub_, *instance_segmentation_sub_);
camera_info_sync_policy_ =new message_filters::Synchronizer<CameraInfoSyncPolicy>(CameraInfoSyncPolicy(kQueueSize), *depth_info_sub_, *rgb_info_sub_);
4.类对象注册回调函数处理
//_1,_2,_3为占为符,表示传入的参数,这里分别指代传入的rgb、depth、segmentation的ros消息
//this->imageSegmentationCallback(x,y,z)
image_segmentation_sync_policy_->registerCallback(boost::bind(
&DepthSegmentationNode::imageSegmentationCallback, this, _1, _2, _3));
camera_info_sync_policy_->registerCallback(
boost::bind(&DepthSegmentationNode::cameraInfoCallback, this, _1, _2));