As a general rule we don't return images from service calls. See <a href="http://www.ros.org/wiki/polled_camera">polled_camera</a> for reasons why, and another model for requesting images by service.<br><br>The upcoming <a href="http://www.ros.org/wiki/cv_bridge_redesign">redesigned C++ API</a> 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.<br>
<br>Patrick<br><br><div class="gmail_quote">On Fri, Nov 19, 2010 at 1:24 PM, Josh Faust <span dir="ltr"><<a href="mailto:jfaust@willowgarage.com">jfaust@willowgarage.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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?<div><br></div><div>In the meantime you could use a null deleter and create a shared_ptr out of the image:</div>


<div><br></div><div>void nullDeleter(void*) {}</div><div>boost::shared_ptr<sensor_msgs::Image> image_ptr(&srv.response.left_image, nullDeleter);</div><div><br></div><font color="#888888"><div>Josh</div></font><div>
<div></div><div class="h5"><div><br><div class="gmail_quote">

On Fri, Nov 19, 2010 at 1:18 PM, Josh Faust <span dir="ltr"><<a href="mailto:jfaust@willowgarage.com" target="_blank">jfaust@willowgarage.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


What was the compile error you got originally?  That's not a valid cast to be making.<div><br></div><div>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?</div>



<div><br></div><div><font color="#888888">Josh<br><br></font><div class="gmail_quote"><div>On Fri, Nov 19, 2010 at 12:49 PM, Soonhac Hong <span dir="ltr"><<a href="mailto:soonhac.hong@gmail.com" target="_blank">soonhac.hong@gmail.com</a>></span> wrote:<br>


</div><div><div></div><div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi all,<br>
<br>
I'm trying to convert sensor_msgs/Image to the opencv image. The<br>
sensor_msgs/Image is defined in the ros service as follows.<br>
<br>
<temp_srv.srv><br>
bool isColor<br>
----<br>
sensor_msgs/Image left_image<br>
<br>
<br>
The problem has happened at the following code.<br>
<br>
IplImage* left_image = bridge_.imgMsgToCv((const<br>
sensor_msgs::ImageConstPtr&) srv.response.left_image, "passthrough");<br>
<br>
Without the casting,(const sensor_msgs::ImageConstPtr&), there was an<br>
compile error. With the casting, there is a runtime error, segmentation<br>
fault. Is there anyone to know how to get the<br>
sensor_msgs::ImageConstPtr& of the sensor_msgs/Image which is defined in<br>
the ros service?<br>
<br>
I confirmed that there are the proper value of each pixel in the<br>
srv.response.left_image.data[] as well as srv.response.left_image.width<br>
and srv.response.left_image.hight.<br>
<br>
Thank you for any comments.<br>
<br>
Best,<br>
Soonhac<br>
<br>
_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@code.ros.org" target="_blank">ros-users@code.ros.org</a><br>
<a href="https://code.ros.org/mailman/listinfo/ros-users" target="_blank">https://code.ros.org/mailman/listinfo/ros-users</a><br>
</blockquote></div></div></div><br></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@code.ros.org">ros-users@code.ros.org</a><br>
<a href="https://code.ros.org/mailman/listinfo/ros-users" target="_blank">https://code.ros.org/mailman/listinfo/ros-users</a><br>
<br></blockquote></div><br>