Subscriber C++ to camera_info
Hi everyone,
I followed the tutorial on the subscriber to the Image subscriber here: http://wiki.ros.org/image_transport/Tutorials/SubscribingToImages
It worked but now I would like to add a subscriber to the camera_info topic.
I tried to understand how to do it but I didn't succeed. Basically I found someone who is doing it through the message_filters::Subscriber
but I didn't understand how to do it.
Could you help me please?
The code that I have is the following right now:
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/CameraInfo.h>
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
try
{
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
cv::waitKey(30);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
cv::namedWindow("view");
cv::startWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("camera/image_raw", 1, imageCallback);
ros::Subscriber<sensor_msgs::CameraInfo> sub_cameraInfo(); // this is wrong
message_filters::Subscriber<sensor_msgs::CameraInfo> sub_cameraInfo ; // I don't know how to finish this!
ros::spin();
cv::destroyWindow("view");
}
Thanks a lot for your help.
Asked by fabbro on 2016-12-11 16:38:41 UTC
Comments
Did you check the ROS wiki? It actually has exactly what you are looking for as an example.
Asked by mgruhler on 2016-12-12 02:52:51 UTC
Hi, thanks for the reply. What is the difference between:
and
Thanks
Asked by fabbro on 2016-12-12 04:40:51 UTC
Ok I understood that:
Example (C++)
is the equivalent of:
Asked by fabbro on 2016-12-12 05:05:51 UTC