【问题标题】:Point Cloud not updating点云不更新
【发布时间】:2020-12-20 00:34:22
【问题描述】:

我是点云处理的新手。我正在尝试将激光雷达点云与已同步到激光雷达的相机捕获的图像数据对齐。作为第一步,我想使用下面的脚本渲染我的激光雷达点云,但不更新它。 viewer-> spin() 似乎不起作用。任何帮助将不胜感激。

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
static const std::string OPENCV_WINDOW = "Image window";
using namespace sensor_msgs;
using namespace message_filters;

void callback(const ImageConstPtr& image1, const boost::shared_ptr<const sensor_msgs::PointCloud2>& input)
 {
   pcl::PCLPointCloud2 pcl_pc2;
   pcl_conversions::toPCL(*input,pcl_pc2);
   pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
   pcl::fromPCLPointCloud2(pcl_pc2,*temp_cloud);
   pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
   viewer.showCloud(temp_cloud);
   while (!viewer.wasStopped ())
   {
   }
 }
int main(int argc, char** argv)
{
  ros::init(argc, argv, "vision_node");
  ros::NodeHandle nh;
  message_filters::Subscriber<Image> image1_sub(nh, "/pylon_camera_node/image_rect_color", 1);
  message_filters::Subscriber<sensor_msgs::PointCloud2> lidar_sub(nh, "/os1_cloud_node/points", 1);
  typedef sync_policies::ApproximateTime<Image, PointCloud2> MySyncPolicy;
  Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), image1_sub, lidar_sub);
  sync.registerCallback(boost::bind(&callback, _1, _2));
  ros::spin();
  return 0;
}

【问题讨论】:

  • 您是否已经在 rviz 或仅使用 rostopic echo 验证了它的工作原理,即更新?顺便说一句,您没有显示订阅更新的代码。实际上,您似乎在应该由订阅者调用的回调内部旋转。如果是这样,那么您将不会收到新数据,因为您正在阻止。你能添加你的订阅者代码,然后我们可以告诉你在哪里放置旋转/while?
  • @ChristianFritz 非常感谢您的回复。我已经用 rviz 和 rostopic echo 进行了验证,它会发布数据。我已经包含了整个代码。再次感谢
  • 是的,您肯定想在回调中删除该 while 循环。回调需要返回才能使用新数据再次调用。您还需要在回调之外创建查看器,并且只更新数据以在该函数内部显示。
  • @ChristianFritz 有没有可用的例子?
  • 我添加了一个简化示例作为答案。希望对您有所帮助。

标签: ros point-cloud-library point-clouds lidar


【解决方案1】:

以下是您的控件需要如何流动的简化示例。它不包含与您拥有的图像的同步(我没有示例数据来测试它)。但我认为它向您展示了您的需求。正如 cmets 中所说,关键是只创建一次查看器,然后在新数据到达时对其进行更新。

#include <ros/ros.h>
#include <pcl/point_cloud.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/visualization/cloud_viewer.h>
#include <sensor_msgs/PointCloud2.h>

pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");

/** receives the point cloud from the subscriber and updates the viewer with it */
void callback(const sensor_msgs::PointCloud2ConstPtr& cloud_msg) {
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
  pcl_conversions::toPCL(*cloud_msg, *cloud);
  pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::fromPCLPointCloud2(*cloud, *temp_cloud);
  viewer.showCloud(temp_cloud);
}

int main(int argc, char** argv) {
  ros::init(argc, argv, "vision_node");
  ros::NodeHandle nh;
  ros::Subscriber sub = nh.subscribe("/points", 1, callback);
  ros::spin();
  return 0;
}

【讨论】:

  • 非常感谢!我会测试一下。
猜你喜欢
  • 2018-06-25
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
相关资源
最近更新 更多