A test of image_transport subscriber and publisher get mutex lock error when the program terminates (core dumped)

asked 2019-07-26 13:23:04 -0500

Franz gravatar image

A test of image_transport subscriber and publisher get error when the program terminates (core dumped)

Hello everyone, I am a newcomer to ros. I am trying to learn the image_transport package and write a very simple cpp, which can reduce the fps of a video topic without increasing too much computing. I used almost the same syntax in the tutorial. It seems to work fine, but when I terminated it I got the following error.

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost: mutex lock failed in pthread_mutex_lock: Invalid argument
Terminated (core dumped)

Does anyone know why? How can I correct it?

In addition, can anyone recommend a package that subscribes a video topic without increasing too much computing, changes the fps, and then republishes the new video to a new topic?

I appreciate your help.

#include <ros ros.h="">
#include <image_transport image_transport.h="">

image_transport::Publisher pub;
image_transport::Subscriber sub;
int i = 0;

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
    if(i == 0 || i == 9)
    { 
      if(i == 0)
      { 
        pub.publish(msg);
        i ++;
      }
      else
      {
        i = 0;
      }      
    }
    else
    {
      i ++;       
    }
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "change_video_fps");

  ros::NodeHandle nh;
  image_transport::ImageTransport it(nh);
  ::pub = it.advertise("fps_changed/image", 1);
  ::sub = it.subscribe("cam/image", 1, imageCallback);
  ros::spin();
}
edit retag flag offensive close merge delete

Comments

can anyone recommend a package that subscribes a video topic without increasing too much computing, changes the fps, and then republishes the new video to a new topic?

This would best be done using a nodelet, and there is support for throttle in nodelet_topic_tools.

gvdhoorn gravatar image gvdhoorn  ( 2019-07-28 12:43:00 -0500 )edit

Thank you, I will take a look and try it.

Franz gravatar image Franz  ( 2019-07-30 02:10:01 -0500 )edit