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

I created a package to load a .png to rviz but every time I add an image visualization to rviz and change the image topic, rivz crashes. does anyone see the problem ?

asked 2018-01-08 11:59:07 -0500

ixorim gravatar image
#include <ros/ros.h>
#include <sensor_msgs/image_encodings.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>


int main(int argc, char** argv)
{
  ros::init(argc, argv, "image_publisher");
  ros::NodeHandle n;
  image_transport::ImageTransport it(n);
  image_transport::Publisher pub = it.advertise("/AS_logo", 1);
  cv::Mat image = cv::imread("/home/kamal/ROS_Work/1.png", CV_LOAD_IMAGE_COLOR);

 if( image.empty() )                      // Check for invalid input
{
    ROS_INFO("Could not open or find the image");
    return -1;
}


 sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();

 ros::Rate loop_rate(1);
 while (n.ok()) {
   pub.publish(msg);
   ROS_INFO("ImageMsg Sent.");
   ROS_INFO("Subscribers: %d", pub.getNumSubscribers());
   ros::spinOnce();
   loop_rate.sleep();
 }

ros::spin();
return 0;

}

edit retag flag offensive close merge delete

Comments

Hi!

I just compiled your code and it worked perfect with this image: https://www.robotigniteacademy.com/st...

Could you run rosrun rviz rviz --verbose to see if there is any "error" log?

Ruben Alves gravatar image Ruben Alves  ( 2018-01-08 16:44:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-08 20:46:59 -0500

ixorim gravatar image

Thank you, I got it to work, it was the image size I had to resize it.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-01-08 11:59:07 -0500

Seen: 267 times

Last updated: Jan 08 '18