ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
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 image TFinleyosu  ( 2014-02-11 11:25:39 -0600 )edit

3 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

Comments

Thanks for the answer. How to publish images in a folder continuously?

Mohammad gravatar image Mohammad  ( 2021-03-08 16:33:51 -0600 )edit

Try out https://github.com/lucasw/image_manip...

rosrun image_manip image_folder_publisher.py _folder:=`pwd`

and there are likely more to be found elsewhere

lucasw gravatar image lucasw  ( 2022-05-19 12:07:29 -0600 )edit
3

answered 2022-05-13 11:55:55 -0600

Beshari gravatar image

updated 2022-05-13 17:36:49 -0600

lucasw gravatar image

There is a node for this:

rosrun image_publisher image_publisher /absolute/path.png
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

Comments

Thanks for the answer. How to publish images in a folder continuously?

Mohammad gravatar image Mohammad  ( 2021-03-08 16:33:04 -0600 )edit

@Mohammad did you figure this out?

NecessaryThat gravatar image NecessaryThat  ( 2021-03-26 13:56:23 -0600 )edit

Question Tools

3 followers

Stats

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

Seen: 12,232 times

Last updated: May 13 '22