c++ 可视化传感器_msgs/PointCloud 2

xfyts7mz  于 2023-05-02  发布在  其他
关注(0)|答案(1)|浏览(100)

我尝试在qtvtk小部件上可视化实时sensor_msgs/PointCloud 2,而不是从阅读。pcd文件。我将分享一个代码的例子,从。pcd文件。

void MainWindow::imageShowLIDAR( const sensor_msgs::PointCloud2& msg)
{
    //std::cout << "carico file" << std::endl;

    std::cout << "imageshow lidar initiated" << std::endl;
    
    cloud_pcl.reset (new PointCloudT);
    cloud_pcl->resize (200);
    red   = 128;
    green = 128;
    blue  = 128;
    pcl::io::loadPCDFile("/home/rack_dl/RCEDS_V5/Data/pcl1.pcd", *cloud_pcl);
    //pcl::io::loadPCDFile("/home/rack_dl/RCEDS_V5/Data/Reg.pcd", *cloud_pcl);
    for (auto& point: *cloud_pcl)
  {
    //point.x = 1024 * rand () / (RAND_MAX + 1.0f);
    //point.y = 1024 * rand () / (RAND_MAX + 1.0f);
    //point.z = 1024 * rand () / (RAND_MAX + 1.0f);

    point.r = red;
    point.g = green;
    point.b = blue;
    
  }
    
    viewer_pcl.reset(new pcl::visualization::PCLVisualizer("viewer_pcl", false));
    //Set viewer settings

    viewer_pcl->addCoordinateSystem(3.0, "coordinate");
    viewer_pcl->setShowFPS(false);
    viewer_pcl->setBackgroundColor(0.0, 0.0, 0.0, 0);
    //viewer_pcl->setCameraPosition(0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0);
    ui.LIDAR_Widget->SetRenderWindow(viewer_pcl->getRenderWindow());
    viewer_pcl->setupInteractor(ui.LIDAR_Widget->GetInteractor(), ui.LIDAR_Widget->GetRenderWindow());
    viewer_pcl->addPointCloud (cloud_pcl, "cloud");
    viewer_pcl->resetCamera ();
    ui.LIDAR_Widget->update();
    
}

我正在接收sensor_msgs/PointCloud 2上的数据
而不是从阅读。pcd文件我想实时可视化.我该怎么做?

yhuiod9q

yhuiod9q1#

正如@伊格纳西奥所说。你应该看看pcl_conversions包!
下面是ROS 2中的回调示例:

#include <pcl_conversions/pcl_conversions.h>
void cloud_callback(const sensor_msgs::msg::PointCloud2::SharedPtr &msg){
  pcl::PointCloud<pcl::PointXYZRGB> pcl_cloud;

  pcl::fromROSMsg(*msg,pcl_cloud);

  // pcl_cloud -> point_cloud as pcl object

  // code here
  //    ...
  // code here

  sensor_msgs::msg::PointCloud2 sensor_msgs_cloud;

  pcl::toROSMsg(pcl_cloud,sensor_msgs_cloud);

  // sensor_msgs_cloud -> point_cloud as sensor_msgs object
}

对于ROS 1,您应该稍微更改#include和名称空间。但代码几乎是一样的。您可以看一下github repo示例,了解它应该是什么样子。
对于实时可视化更新,您应该查看official pcl tutorial

相关问题