Ask Your Question
0

How to change ImageConstPtr data?

asked Feb 22

Konstantin Cherenkov gravatar image Konstantin Cherenkov
1

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.

delete close flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
1

answered Feb 22

alfa_80 gravatar image alfa_80
609 1 14 37

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.

link delete flag offensive edit

Comments

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

alfa_80 (Feb 22)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 (Feb 23)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 (Feb 23)edit
4

answered Feb 22

TomTUM gravatar image TomTUM flag of Germany
306 5 11
http://ias.in.tum.de/peop...

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.

link delete flag offensive edit
0

answered Feb 22

Dan Lazewatsky gravatar image Dan Lazewatsky
2269 15 27 45
http://cse.wustl.edu/~dla...

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

link delete flag offensive edit
0

answered Feb 22

Eddit gravatar image Eddit
39 3

updated Feb 22

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);

}

link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Follow

subscribe to rss feed

Stats

Asked: Feb 22

Seen: 88 times

Last updated: Feb 22