Recently, I recorded a large set of image data using a rosbag, but I am not able to get the subscriber working for the compressed image topic. I did not save the image_raw topic. I only saved the compressed topic. These are the topics contained in my rosbag file.
/usb_cam/camera_info
/usb_cam/image_raw/compressed
I am able to extract the images from the bag file and save to disk using a command that looks something like this
rosrun image_view extract_images _sec_per_frame:=0.001 image:=/usb_cam/image_raw _image_transport:=compressed
I do want to note that the number of /usb_cam/image_raw/compressed messages in my bag file is 16078 and after executing that command the number of images saved to disk is only 16052
Regardless, the main issue is that I am not able to get the images through a subscriber in any of my nodes. I am able to get the images in my subscriber in real time using the image_raw topic, but I can't get this to work using only the compressed topic. I have looked at several tutorials, but I am still not able to figure it out. I think I am missing something very simple. Here is my code for the simple subscriber that will not work.
class Images
{
public:
image_transport::Subscriber sub_image;these
Images()
{
ros::NodeHandle node;
image_transport::ImageTransport it(node);
sub_image = it.subscribe("/usb_cam/image_raw/compressed", 1, &Images::imageCallback, this);
}
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, "my_node");
ROS_INFO("my_node running...");
Images images;
ros::spin();
return 0;
}
If I run this code I get the following error messages:
[ WARN] [1459295416.022612760]: [image_transport] It looks like you are trying to subscribe directly to a transport-specific image topic '/usb_cam/image_raw/compressed', in which case you will likely get a connection error. Try subscribing to the base topic '/usb_cam/image_raw' instead with parameter ~image_transport set to 'compressed' (on the command line, _image_transport:=compressed). See http://ros.org/wiki/image_transport for details.
I don't know how to subscribe to '/usb_cam/image_raw' instead because this topic does not exist in my rosbag file. If I do subscribe to '/usb_cam/image_raw', then the callback function never triggers because the topic doesn't exist. How do I do this?
Originally posted by Ralff on ROS Answers with karma: 280 on 2016-03-29
Post score: 2