Ask Your Question
0

How to change ImageConstPtr data?

asked 2012-02-21 22:04:33 -0600

Konstantin Cherenkov gravatar image

Hi all!

Please explain me how could I change raw data in ImageConstPtr& object? I have a function like:

void filterImage (const sensor_msgs::ImageConstPtr& rgb_msg)
{
  // something like rgb_msg->data[100] = 0;
}

So, I should change image data, and then pass rgb_msg to other functions.

I see deprecated functions get_data_vec and set_data_vec in Image.h file, but looks like I could not use them cause I have const modifier on object, and set_data_vec is non-const function.

Thank you.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2012-02-21 22:46:11 -0600

alfa_80 gravatar image

You might want to try something like below:

void filterImage (const sensor_msgs::ImageConstPtr& rgb_msg)
{
    sensor_msgs::Image current_rgb_msg;
    current_rgb_msg = *rgb_msg;   
}

You can further manipulate the value from current_rgb_msg variable.

edit flag offensive delete link more

Comments

It's better to put the declaration of "current_rgb_msg" in class scope.

alfa_80 gravatar imagealfa_80 ( 2012-02-21 22:49:53 -0600 )edit

As I understood, "current_rgb_msg" is a copy of object, referenced by "rgb_msg". Ok, that means, that all changes would be actually for "current_rgb_msg" object. Could you please explain, how to convert "current_rgb_msg" to "const sensor_msgs::ImageConstPtr&" after all changes? Thanks.

Konstantin Cherenkov gravatar imageKonstantin Cherenkov ( 2012-02-22 20:18:57 -0600 )edit

You cannot convert/overwrite the incoming "rgb_msg", because it is a constant value(it's read-only variable). I'm not so into openCV, I think, you can try what dlaz and Eddit suggested, that's by using straightaway cv_bridge for further processing.

alfa_80 gravatar imagealfa_80 ( 2012-02-22 20:44:25 -0600 )edit
4

answered 2012-02-21 22:16:19 -0600

TomTUM gravatar image

You should probably copy the data to another sensor_msgs::Image and then modify it, as you are supposed to read only from const data.

edit flag offensive delete link more
0

answered 2012-02-22 04:27:18 -0600

If you're doing any real image processing, you should use cv_bridge to convert it to an OpenCV type first.

edit flag offensive delete link more
0

answered 2012-02-22 17:02:10 -0600

Eddit gravatar image

updated 2012-02-22 17:04:47 -0600

Here is the example how to copy your ImageConstPtr& object to opencv obj:

void filterImage (const sensor_msgs::ImageConstPtr& rgb_msg)

{

cv::namedWindow(WINDOW);

cv_bridge::CvImagePtr cv_ptr;

try {

cv_ptr = cv_bridge::toCvCopy(rgb_msg, enc::BGR8);

}

catch (cv_bridge::Exception& e)

{

ROS_ERROR("cv_bridge exception: %s", e.what()); return; }

cv::imshow(WINDOW, cv_ptr->image);

cv::waitKey(10);

}

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-02-21 22:04:33 -0600

Seen: 2,748 times

Last updated: Feb 22 '12