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/T...
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.
Did you check the ROS wiki? It actually has exactly what you are looking for as an example.
Hi, thanks for the reply. What is the difference between:
and
Thanks
Ok I understood that:
Example (C++)
is the equivalent of: