Hello I'm trying to synchronize 2 topic(color/image and semantic_image) but unfortantelly the callback function doesn't work , here is my code ;
#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/approximate_time.h>
#include <sensor_msgs/Image.h>
using namespace sensor_msgs;
using namespace message_filters;
void callback(const ImageConstPtr& image1, const ImageConstPtr& image2)
{
// Solve all of perception here...
std::cout<<"CallBack works ...";
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "vision_node");
ros::NodeHandle nh;
message_filters::Subscriber<Image> image1_sub(nh, "semantic_pcl/semantic_image", 1);
message_filters::Subscriber<Image> image2_sub(nh, "camera/color/image_raw", 1);
typedef sync_policies::ApproximateTime<Image, Image> MySyncPolicy;
// ApproximateTime takes a queue size as its constructor argument, hence MySyncPolicy(10)
Synchronizer<MySyncPolicy> sync(MySyncPolicy(30), image1_sub, image2_sub);
sync.registerCallback(boost::bind(&callback, _1, _2));
std::cout<<"Sync Image ..."<<std::endl;
ros::spin();
return 0;
}
Here is more details of these 2 topics(when running $ rostopic hz & echo ...) ;
Image_raw ;
$ rostopic echo /camera/color/image_raw
header:
seq: 47205
stamp:
secs: 1615561761
nsecs: 128132582
frame_id: "camera_color_optical_frame"
height: 720
width: 1280
encoding: "rgb8"
is_bigendian: 0
step: 3840
data: [131, 146, 132, 132, 147, 133,
$ rostopic hz /camera/color/image_raw
subscribed to [/camera/color/image_raw]
average rate: 30.187
min: 0.025s max: 0.044s std dev: 0.00285s window: 28
average rate: 30.076
min: 0.025s max: 0.044s std dev: 0.00226s
semantic_image :
$ rostopic echo /semantic_pcl/semantic_image
header:
seq: 18
stamp:
secs: 0
nsecs: 0
frame_id: ''
height: 480
width: 640
encoding: "bgr8"
is_bigendian: 0
step: 1920
data: [128, 192, 64, 128, 192,
$ rostopic hz /semantic_pcl/semantic_image
subscribed to [/semantic_pcl/semantic_image]
no new messages
no new messages
average rate: 0.386
min: 2.591s max: 2.591s std dev: 0.00000s window: 2
no new messages
Originally posted by Ahmad Kheirandish on ROS Answers with karma: 3 on 2021-04-06
Post score: 0