当前位置:   article > 正文

rosbag record 报错:rosbag record buffer exceeded. Dropping oldest queued message.

rosbag record buffer exceeded. dropping oldest queued message.

问题描述: 

 针对上面的问题解决的方法有:

方法1:换个读写速度更快的SSD硬盘

--------------------------亲测可用---------------------------

方法2:压缩原始图像大小

安装插件

sudo apt-get install ros-melodic-image-transport-plugins

创建catkin_ws工作空间下的功能包,名字    image_compressor

launch/start_compressor.launch

start_compressor.launch

  1. <launch>
  2. <node name="image_compressor_node" pkg="image_compressor" type="image_compressor_node" output="screen"/>
  3. </launch>

src/image_compressor_node.cpp

image_compressor_node.cpp

  1. #include <ros/ros.h>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <cv_bridge/cv_bridge.h>
  4. #include <sensor_msgs/CompressedImage.h>
  5. #include <opencv2/imgcodecs.hpp>
  6. class ImageCompressorNode
  7. {
  8. public:
  9. ImageCompressorNode()
  10. {
  11. // 订阅压缩图像话题
  12. for (const auto& topic : compressed_input_topics_)
  13. {
  14. subscribers_.push_back(nh_.subscribe<sensor_msgs::CompressedImage>(topic, 1, &ImageCompressorNode::compressedImageCallback, this));
  15. }
  16. // 发布压缩后的图像话题
  17. for (const auto& topic : compressed_output_topics_)
  18. {
  19. compressed_publishers_.push_back(nh_.advertise<sensor_msgs::CompressedImage>(topic, 1));
  20. }
  21. }
  22. private:
  23. void compressedImageCallback(const sensor_msgs::CompressedImageConstPtr& msg)
  24. {
  25. try
  26. {
  27. cv::Mat image = cv::imdecode(cv::Mat(msg->data), cv::IMREAD_COLOR);
  28. if(image.empty()) {
  29. ROS_ERROR("Failed to decode image");
  30. return;
  31. }
  32. std::vector<uchar> buffer;
  33. std::vector<int> compression_params;
  34. compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
  35. compression_params.push_back(95); // Quality from 0 to 100
  36. cv::imencode(".jpg", image, buffer, compression_params);
  37. sensor_msgs::CompressedImage compressed_msg;
  38. compressed_msg.header = msg->header;
  39. compressed_msg.format = "jpeg";
  40. compressed_msg.data = buffer;
  41. // 发布压缩后的图像
  42. std::string topic = msg->header.frame_id;
  43. auto it = std::find(compressed_input_topics_.begin(), compressed_input_topics_.end(), topic);
  44. if (it != compressed_input_topics_.end())
  45. {
  46. size_t index = std::distance(compressed_input_topics_.begin(), it);
  47. compressed_publishers_[index].publish(compressed_msg);
  48. }
  49. }
  50. catch (cv_bridge::Exception& e)
  51. {
  52. ROS_ERROR("Could not convert to image: %s", e.what());
  53. }
  54. }
  55. ros::NodeHandle nh_;
  56. std::vector<std::string> compressed_input_topics_ = {
  57. "/usb_cam1/image_raw/compressed",
  58. "/usb_cam2/image_raw/compressed",
  59. "/usb_cam3/image_raw/compressed",
  60. "/usb_cam4/image_raw/compressed",
  61. "/usb_cam5/image_raw/compressed"
  62. };
  63. std::vector<std::string> compressed_output_topics_ = {
  64. "/usb_cam1/image_compressed",
  65. "/usb_cam2/image_compressed",
  66. "/usb_cam3/image_compressed",
  67. "/usb_cam4/image_compressed",
  68. "/usb_cam5/image_compressed"
  69. };
  70. std::vector<ros::Subscriber> subscribers_;
  71. std::vector<ros::Publisher> compressed_publishers_;
  72. };
  73. int main(int argc, char **argv)
  74. {
  75. ros::init(argc, argv, "image_compressor_node");
  76. ImageCompressorNode node;
  77. ros::spin();
  78. return 0;
  79. }

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.0.2)
  2. project(image_compressor)
  3. find_package(catkin REQUIRED COMPONENTS
  4. roscpp
  5. sensor_msgs
  6. cv_bridge
  7. image_transport
  8. )
  9. find_package(OpenCV REQUIRED)
  10. catkin_package(
  11. CATKIN_DEPENDS roscpp sensor_msgs cv_bridge image_transport
  12. )
  13. include_directories(
  14. ${catkin_INCLUDE_DIRS}
  15. ${OpenCV_INCLUDE_DIRS}
  16. )
  17. add_executable(${PROJECT_NAME}_node src/image_compressor_node.cpp)
  18. target_link_libraries(${PROJECT_NAME}_node
  19. ${catkin_LIBRARIES}
  20. ${OpenCV_LIBRARIES}
  21. )

package.xml

  1. <?xml version="1.0"?>
  2. <package format="2">
  3. <name>image_compressor</name>
  4. <version>0.0.0</version>
  5. <description>The image_compressor package</description>
  6. <maintainer email="user@todo.todo">user</maintainer>
  7. <license>TODO</license>
  8. <buildtool_depend>catkin</buildtool_depend>
  9. <build_depend>roscpp</build_depend>
  10. <build_depend>sensor_msgs</build_depend>
  11. <build_depend>cv_bridge</build_depend>
  12. <build_depend>image_transport</build_depend>
  13. <exec_depend>roscpp</exec_depend>
  14. <exec_depend>sensor_msgs</exec_depend>
  15. <exec_depend>cv_bridge</exec_depend>
  16. <exec_depend>image_transport</exec_depend>
  17. </package>

  1. cd ~catkin_ws
  2. catkin_make
  3. source devel/setup.bash 
  4. roslaunch multi_cam multi_cam.launch 
  5. roslaunch image_compressor start_compressor.launch

查看话题如下:

录用包的时候将

rosbag record /usb_cam1/image_raw /usb_cam2/image_raw /usb_cam3/image_raw /usb_cam4/image_raw  /usb_cam5/image_raw

换成

rosbag record /usb_cam1/image_raw/compressed /usb_cam2/image_raw/compressed /usb_cam3/image_raw/compressed /usb_cam4/image_raw/compressed /usb_cam5/image_raw/compressed

--------------------------亲测可用,但是画质有所损伤---------------------------

方法3: 提高rosbag的缓存空间

rosbag record -b 4096 /usb_cam1/image_raw /usb_cam2/image_raw /usb_cam3/image_raw /usb_cam4/image_raw /usb_cam5/image_raw

--------------------------此方法效果不太明显---------------------------

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/981074
推荐阅读
相关标签
  

闽ICP备14008679号