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

Revision history [back]

click to hide/show revision 1
initial version

According to this answer on Stack Overflow your function call is incorrect.

Here's what the accepted answer says

A shared_ptr to an object owning the sensor_msgs::Image and the other

A shared_ptr to a sensor_msgs::Image message You are providing neither one nor the other.

In your case, the first option should work, which expects the image as first parameter and the shared_ptr to the object owning the image (which is msg) as second parameter:

cv_bridge::toCvShare(msg->color, msg, "bgr8")

In short, try changing

cv::imshow("view", cv_bridge::toCvShare(srv.response.img, "bgr8")->image);

to

cv::imshow("view", cv_bridge::toCvShare(srv.response.img.color, msg, "bgr8"));

(Change srv.response.img.color to whatever the equivalent is for your service message, since I don't know exactly how yours is formatted.)

According to this answer on Stack Overflow your function call is incorrect.

Here's what the accepted answer says

A shared_ptr to an object owning the sensor_msgs::Image and the other

A shared_ptr to a sensor_msgs::Image message You are providing neither one nor the other.

In your case, the first option should work, which expects the image as first parameter and the shared_ptr to the object owning the image (which is msg) as second parameter:

cv_bridge::toCvShare(msg->color, msg, "bgr8")

In short, try changing

cv::imshow("view", cv_bridge::toCvShare(srv.response.img, "bgr8")->image);

to

cv::imshow("view", cv_bridge::toCvShare(srv.response.img.color, msg, srv.response, "bgr8"));

(Change srv.response.img.color and srv.response to whatever the equivalent is for your service message, since I don't know exactly how yours is formatted.)