Robotics StackExchange | Archived questions

advertise image causes Segmentation fault (core dumped)

I found it will have an error shown in terminals: Segmentation fault (core dumped) when ImageTransport advertise. Environments: Ubuntu 14.04. ROS Indigo, use my own build opencv. Could someone have encountered the same bug? Any advise is appreciated. Thanks.

The snippet of code:

static const std::string TOPIC_NAME = "camera/image";
int publishImage(std::string filepath)
{
  image = imread(filepath, CV_LOAD_IMAGE_COLOR);   // Read the file
  if(!image.data)                              // Check for invalid input
  {
       std::cout << "Could not open or find the image" << std::endl ;
      return -1;
  }
  ros::NodeHandle nh;
  image_transport::ImageTransport it(nh);
  **image_transport::Publisher pub = it.advertise(TOPIC_NAME, 1);**
  sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
  ros::Rate loop_rate(5);
  while (nh.ok()) {
       pub.publish(msg);
       ros::spinOnce();
       loop_rate.sleep();
  }

}

Asked by tzutalin on 2015-04-30 09:54:21 UTC

Comments

use my own build opencv

have you built image_transport (and all associated pkgs) also from source? Segfaults are common errors if you mix-and-match from-source and debian installed libraries / binaries.

Asked by gvdhoorn on 2015-04-30 10:59:11 UTC

Thanks!! As you said, I downloaded and built the image_transport source in my catkin_ws before. After I remove the source and build again, the Segfaults didn't happen.

Asked by tzutalin on 2015-04-30 19:04:21 UTC

Answers