advertise image causes Segmentation fault (core dumped) [closed]

asked 2015-04-30 09:54:21 -0500

tzutalin gravatar image

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();
  }

}

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by tzutalin
close date 2015-04-30 19:07:49.854435

Comments

1

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.

gvdhoorn gravatar image gvdhoorn  ( 2015-04-30 10:59:11 -0500 )edit

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.

tzutalin gravatar image tzutalin  ( 2015-04-30 19:04:21 -0500 )edit