How to get image from custom server using service?
Hello People,
I am trying to pass image from server to a client. The code complies when I use cv_bridge::toCvCopy, but it says core dumped when I actually call the image from the server. So I am currently trying to do the same thing using cv_bridge::toCvShare, but it throws following error -
error: no matching function for call to ‘toCvShare(robot_vision::request_imageResponse_<std::allocator<void> >::_img_type&, const char [5])’ cv::imshow("view", cv_bridge::toCvShare(srv.response.img, "bgr8")->image);
Inorder to check my server please check my previous question (I have updated the code with working one). My code for client is below -
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include "sensor_msgs/Image.h"
#include <opencv2/imgproc/imgproc.hpp>
#include "robot_vision/request_image.h"
#include <cstdlib>
#include <iostream>
namespace enc = sensor_msgs::image_encodings;
cv_bridge::CvImagePtr cv_ptr;
int main(int argc,char **argv)
{
ros::init(argc,argv,"image_client_node");
ros::NodeHandle nh;
ros::ServiceClient client = nh.serviceClient<robot_vision::request_image>("image_server");
robot_vision::request_image srv;
srv.request.request_msg = true;
if(client.call(srv))
{
ROS_INFO("Service initiated");
try
{
//cv_ptr = cv_bridge::toCvCopy(srv.response.img, sensor_msgs::image_encodings::BGR8);
cv::imshow("view", cv_bridge::toCvShare(srv.response.img, "bgr8")->image);
cv::waitKey(30);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("cv_bridge exception: %s", e.what());
//return;
}
}
else
{
ROS_ERROR("Failed to call service image_server");
return 1;
}
ros::spinOnce();
return 0;
}
Please use the Preformat Text (
101010
) button to make your code readable. http://wiki.ros.org/Support#DoWill do it, Thanks @jayess
You mention a previous question but I don't see a link to one...
Done @jayess