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

Edit encoding of sensor_msgs/Image message

asked 2019-03-21 12:09:41 -0500

eirikaso gravatar image

updated 2019-03-21 12:22:17 -0500

I have a sensor_msgs/Image message that I'm unable to use with standard ROS packages like stereo_image_proc because the "encoding" is described as "8UC1". I want it to be interpreted as "mono8" and want to change the string in the "encoding" parameter of the message.

void imageCallback(sensor_msgs::ImageConstPtr& msg)
{
    ROS_INFO("Message received");
    msg->encoding.at<std::string>(0,0) = "mono8";
}

When I do it like above I get the error message "type name is not allowed" when compiling. I have tried all sorts of alternatives but can't seem to find it out. Can anyone help me on this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-03-21 13:07:11 -0500

8UC1 is the equivalent openCV encoding of ros' mono8, they describe the same thing. However you must use one with openCV functions and the other with ROS functions.

I think this problem is to do with how you're accessing the variable. There are few problems, it's a const data type so you will not be able to modify it. Even it is wasn't const you should update it as below:

msg->encoding = "mono8";

I don't know what you're trying to do with that line, it looks like you're trying to access a pixel and set it to a type string. Are you trying to convert this ROS image message into an openCV image? If so there is a built in library cv_bridge for doing that with tutorials.

Hope this helps.

edit flag offensive delete link more

Comments

Thank you. I have recorded some .bag files with the Intel realsense camera using their ROS driver. Unfortunately they save them as 8UC1 encoded. I will try to use cv_bridge instead tomorrow, but I got a tip that I should be able to just change the encoding string link

I will try to subscribe, apply cv_bridge, and then publish again

eirikaso gravatar image eirikaso  ( 2019-03-21 16:58:01 -0500 )edit

If you just need change the encoding string. You'll need to first make a non-const copy of the message and then update the encoding as I've shown in my answer, then you will be able to re-publish the updated message

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-03-22 09:58:11 -0500 )edit

Yes, thank you. I just tested it 30 minutes ago and got it working :)

eirikaso gravatar image eirikaso  ( 2019-03-22 10:09:07 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-21 12:09:41 -0500

Seen: 1,384 times

Last updated: Mar 21 '19