ros降低kinect的帧率

在slam过程中,双目摄像头的分辨率默认是640x480@30Hz,而有时我们不需要这么高的分辨率和帧率,因为这样浪费CPU资源和网络带宽。

降低cpu资源有两种方法:

第一种是降低分辨率

ros中kinect有两个驱动1.freenect,2.openni

使用freenect驱动的话,只有两种分辨率

SXGA (1): 1280x1024@15Hz, VGA (2): 640x480@30Hz

使用openni驱动,有12种:

SXGA_15Hz (1): 1280x1024@15Hz, VGA_30Hz (2): 640x480@30Hz, VGA_25Hz (3): 640x480@25Hz, QVGA_25Hz (4): 320x240@25Hz, QVGA_30Hz (5): 320x240@30Hz, QVGA_60Hz (6): 320x240@60Hz, QQVGA_25Hz (7): 160x120@25Hz, QQVGA_30Hz (8): 160x120@30Hz, QQVGA_60Hz (9): 160x120@60Hz


第二种是降低发布到topic上的帧率

采取的方式是直接修改代码

下载openni_camera源码,修改里面的openni_camera/src/nodelets/driver.cpp,修改方案如下:

void DriverNodelet::depthCb(boost::shared_ptr<openni_wrapper::DepthImage> depth_image, void* cookie)
{

 if(0 == (flag_%3))
 {
  ROS_DEBUG("openni::depth call back -1-");

  if (!config_init_)
    return;

  ros::Time time = ros::Time::now () + ros::Duration(config_.depth_time_offset);
  time_stamp_ = time; // for watchdog

  bool publish = false;
  {
      boost::unique_lock<boost::mutex> counter_lock(counter_mutex_);
      depth_frame_counter_++;
      checkFrameCounters();
      publish = publish_depth_;

      if (publish)
          depth_frame_counter_ = 0; // Reset counter if we publish this message to avoid under-throttling
  }

  if (publish)
      publishDepthImage(*depth_image, time);

  publish_depth_ = false;


  ROS_DEBUG("openni::depth call back -2-");
 }

 flag_ ++;
}

这样,就将发布到topic上的depth数据量降低原来的三分之一,从而降低了后续slam,pointcloud等一系列操作的资源占用。


猜你喜欢

转载自blog.csdn.net/sunyoop/article/details/79629592