depth_segmentation节点
包的结构
depth_segmentation
源码
depth_segmentation_node.cpp
- main()函数
定义类DepthSegmentationNode对象,会在构造对象时初始化成员列表:
depth_camera_()
rgb_camera_()
params_()
camra_tracker_(depth_camera_, rgb_camera_)
depth_segmenter_(depth_camera, params)
构造函数的主要逻辑:
加载参数
订阅话题:
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<CvImage> 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);