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 ?
#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;
}
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?