点云未更新

问题描述

我是指点云处理的新手。我正在尝试将激光雷达点云与已同步到激光雷达的相机捕获的图像数据对齐。第一步,我想使用下面的脚本渲染我的激光雷达点云,但不对其进行更新。 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;
}

解决方法

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

#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;
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...