[ros-users] Convert sensor_msgs/Image to the opencv image

Patrick Mihelich mihelich at willowgarage.com
Fri Nov 19 22:16:27 UTC 2010


As a general rule we don't return images from service calls. See
polled_camera <http://www.ros.org/wiki/polled_camera> for reasons why, and
another model for requesting images by service.

The upcoming redesigned C++ API
<http://www.ros.org/wiki/cv_bridge_redesign>does allow converting
directly from a non-shared sensor_msgs/Image if
necessary. That will get merged into unstable soon. You might as well just
use fromImage() for now, since the entire current API is going to be
superseded anway.

Patrick

On Fri, Nov 19, 2010 at 1:24 PM, Josh Faust <jfaust at willowgarage.com> wrote:

> Ah, but it looks like fromImage is deprecated.  Does anyone know why
> there's no longer a way of turning a non-shared pointer of a
> sensor_msgs/Image into a cv image?
>
> In the meantime you could use a null deleter and create a shared_ptr out of
> the image:
>
> void nullDeleter(void*) {}
> boost::shared_ptr<sensor_msgs::Image> image_ptr(&srv.response.left_image,
> nullDeleter);
>
> Josh
>
> On Fri, Nov 19, 2010 at 1:18 PM, Josh Faust <jfaust at willowgarage.com>wrote:
>
>> What was the compile error you got originally?  That's not a valid cast to
>> be making.
>>
>> There's a version of fromImage that just takes the sensor_msgs/Image --
>> are you sure that srv.response.left_image is a sensor_msgs/Image?
>>
>> Josh
>>
>> On Fri, Nov 19, 2010 at 12:49 PM, Soonhac Hong <soonhac.hong at gmail.com>wrote:
>>
>>> Hi all,
>>>
>>> I'm trying to convert sensor_msgs/Image to the opencv image. The
>>> sensor_msgs/Image is defined in the ros service as follows.
>>>
>>> <temp_srv.srv>
>>> bool isColor
>>> ----
>>> sensor_msgs/Image left_image
>>>
>>>
>>> The problem has happened at the following code.
>>>
>>> IplImage* left_image = bridge_.imgMsgToCv((const
>>> sensor_msgs::ImageConstPtr&) srv.response.left_image, "passthrough");
>>>
>>> Without the casting,(const sensor_msgs::ImageConstPtr&), there was an
>>> compile error. With the casting, there is a runtime error, segmentation
>>> fault. Is there anyone to know how to get the
>>> sensor_msgs::ImageConstPtr& of the sensor_msgs/Image which is defined in
>>> the ros service?
>>>
>>> I confirmed that there are the proper value of each pixel in the
>>> srv.response.left_image.data[] as well as srv.response.left_image.width
>>> and srv.response.left_image.hight.
>>>
>>> Thank you for any comments.
>>>
>>> Best,
>>> Soonhac
>>>
>>> _______________________________________________
>>> ros-users mailing list
>>> ros-users at code.ros.org
>>> https://code.ros.org/mailman/listinfo/ros-users
>>>
>>
>>
>
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101119/6a79e913/attachment-0003.html>


More information about the ros-users mailing list