ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

read raw_image compressed uint8[] data

asked 2015-07-29 09:14:06 -0600

Rosewood gravatar image

updated 2015-07-30 09:36:23 -0600

Hello everybody! I'm trying to read the datas of the "sensor_msgs/CompressedImage" message in a c++ program. Therefore I want to read the uint8[] data array. While using the callback function, nothing is happening (e.g. using ROS_INFO, when there is activity). When I'm watching the /image_raw/compressed topic, the data array is infinit. That's why I can't predefine an arraysize. Is there any possibility to get the data into a c++ code to read it separatly? Thanks

   // ROS ///////////////////////////////////////////
 ros::init(argc, argv, "talker_camera_eye");
ROS_INFO("%s", "start");
    ros::NodeHandle n;
   ros::Subscriber translation_sub = n.subscribe("wc_backdrive/camera_eye/image_raw/compressed", 1000, translateCallback);
ros::Publisher translation_pub = n.advertise<sensor_msgs::CompressedImage>("compressed_image", 1000);
  while (ros::ok())
  return 0;


void translateCallback(const sensor_msgs::CompressedImage::ConstPtr& msg)
{ =msg->data;
// =;
ROS_INFO("%s", msg->data.size());ROS_INFO( "test");
for (int i=0; i<msg->data.size();i++){
ROS_INFO( "test");
edit retag flag offensive close merge delete


You should probably post the code of your node, at least the one of the subscriber setup and the callback.

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-29 10:22:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-30 02:45:53 -0600

updated 2015-08-01 09:59:36 -0600

Very classic problem:

 while (ros::ok())
 ros::spinOnce(); ///<<< here, btw, spin does the callbacks!
  //ros::spin(); //That is wrong for that purpose ... you need ros::spinOnce above....
  return 0;

Also try to delete build and devel in your workspace and build it again. Sometimes it also helps, when everything is rebuild.

edit flag offensive delete link more


Thanks cyborg, but he's still not sending data. When I do rostopic echo/image_raw/compressed, the output is data: [255, 216, 255, 224, 0, 16, .... (never ending story) and there is no rosout "test"

Rosewood gravatar image Rosewood  ( 2015-07-30 03:34:15 -0600 )edit

Have you checked for your subscribed topic?

rostopic echo /compressed_image

Of course your output topic will be sending always. Maybe you should consider adding ros::Rate for a setable publish rate

Also check for image transport subcriber/publisher

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-30 04:37:31 -0600 )edit

What does rqt_graph say, is it connected?

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-30 04:39:42 -0600 )edit

The subscribed topic is image_raw/compressed and the output is the data array (see above). The data of my output topic is empty. Rqt says, that my talker node has subscribed for the topic. I think the problem is, that UInt8[] data is a stream.

Rosewood gravatar image Rosewood  ( 2015-07-30 08:07:03 -0600 )edit

No "test" (from your subscriber?) would either mean you still do not receive messages or if you're starting with launchfiles and forgot to add attribute output="screen" to your node or added output="log" instead. Btw ROS_INFO("test") should work as well, why the "%s"?

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-30 08:13:27 -0600 )edit

According to rqt and rosnode info the node has subscribed. I'm starting with rosrun. How would you normally get data from image_raw/compressed, respectively from the UINt8[]. And ignore the "%s"..copied from another command :), but thanks for the hint.

Rosewood gravatar image Rosewood  ( 2015-07-30 08:51:27 -0600 )edit

Can you post your current code with the changes for ros::spinOnce?

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-30 09:07:52 -0600 )edit

Btw. for the image topics it is definitely recommended to use ImageTransport ->

cyborg-x1 gravatar image cyborg-x1  ( 2015-07-30 09:45:04 -0600 )edit

Question Tools

1 follower


Asked: 2015-07-29 09:14:06 -0600

Seen: 1,431 times

Last updated: Aug 01 '15