Ask Your Question
1

publish file to image topic

asked 2013-11-11 04:43:39 -0600

Brad gravatar image

Hi, I want to publish an image file (i.e. image1.jpg) to an image topic I can display in rviz (/camera/image). Can anyone tell me a simple way to do this?

edit retag flag offensive close merge delete

Comments

Did you ever get an example working that you care to share?

TFinleyosu gravatar imageTFinleyosu ( 2014-02-11 11:25:39 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-11-11 05:31:58 -0600

lucasw gravatar image

Use opencv imread on the file and then rosbridge to convert to the sensor_msgs/Image format: http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

edit flag offensive delete link more
2

answered 2014-02-13 12:31:02 -0600

TFinleyosu gravatar image

updated 2014-02-13 12:33:51 -0600

This is what I got working in Hydro

#include <ros/ros.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>

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

    cv_bridge::CvImage cv_image;
    cv_image.image = cv::imread("/home/taylor/Pictures/face.jpg",CV_LOAD_IMAGE_COLOR);
    cv_image.encoding = "bgr8";
    sensor_msgs::Image ros_image;
    cv_image.toImageMsg(ros_image);

  ros::Publisher pub = nh.advertise<sensor_msgs::Image>("/static_image", 1);
  ros::Rate loop_rate(5);

  while (nh.ok()) 
  {
    pub.publish(ros_image);
    loop_rate.sleep();
  }
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2013-11-11 04:43:39 -0600

Seen: 7,615 times

Last updated: Feb 13 '14