Image transfer problem: ros_bridge [closed]

asked 2013-03-06 03:28:26 -0500

Median gravatar image

Hey everyone.

I'm a complete newbie in ROS and am attempting to create a simple publishing/subscribing image platform. Some ROS tutorials regarding this issue use a deprecated protocol (CvBridge) so I'm stuck.

Here is what I have so far:

Image server (adapted from image_transfer tutorial (can't post links)):

int main(int argc, char** argv)
  ros::init(argc, argv, "image_publisher");

  ros::NodeHandle nh;
  image_transport::ImageTransport it(nh);

  cv_bridge::CvImagePtr cv_ptr(new cv_bridge::CvImage);

  cv_ptr->image = cv::imread("socio_32.jpg",CV_LOAD_IMAGE_COLOR);

  image_transport::Publisher pub = it.advertise("/topic_imgtransport", 1);

  sensor_msgs::ImagePtr msg = cv_ptr->toImageMsg();

  ros::Rate loop_rate(5);

  while (nh.ok()) 


And the Image Client (taken from UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages):

class ImageConverter
  ros::NodeHandle nh_;
  image_transport::ImageTransport it_;
  image_transport::Subscriber image_sub_;
  image_transport::Publisher image_pub_;

    : it_(nh_)
    image_pub_ = it_.advertise("out", 1);
    image_sub_ = it_.subscribe("/topic_imgtransport", 1, &ImageConverter::imageCb, this);



  void imageCb(const sensor_msgs::ImageConstPtr& msg)
    cout<<"Hello callback"<<endl;
    cv_bridge::CvImagePtr cv_ptr;
      cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8);
    catch (cv_bridge::Exception& e)
      ROS_ERROR("cv_bridge exception: %s", e.what());

    if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
      cv::circle(cv_ptr->image, cv::Point(50, 50), 10, CV_RGB(255,0,0));

    cv::imshow(WINDOW, cv_ptr->image);


int main(int argc, char** argv)
  ros::init(argc, argv, "image_converter");
  ImageConverter ic;
  return 0;

This doesn't work. Here is the output when I run the client and then the server:

Hello callback

[ERROR] [1362578421.357583807]: cv_bridge exception: Unrecognized image encoding []

In the cv_ptr = cv_bridge::toCvCopy(msg, enc::BGR8); line I tried several encoding types, namely "bgr8", "mono8" and the exception remains the same.

I can visualize the image in the server side, and rostopic echos the correct data about the image.

So obviously the problem is in the way I am receiving the image.

Any thoughts?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2015-11-06 16:09:31.026068