可视化Pointcloud [英] Visualize pointcloud

查看:168
本文介绍了可视化Pointcloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在发现的视差图像上有来自gpu :: reprojectImageTo3D的3D点.我现在想显示这个点云.

I have 3D points from gpu::reprojectImageTo3D on a found disparity image. I would now like to display this pointcloud.

如何将找到的点云从OpenCV转换为sensor_msgs/PointCloud2?

How do I Convert the found pointcloud from OpenCV to sensor_msgs/PointCloud2 ?

我不需要发布pointcloud,这仅用于调试可视化.是否可以像显示来自节点的图像一样显示它?例如使用pcl?这将是最佳选择,因为我的设备在RViz下的效果可能不佳(基于在线阅读).

I do not need to publish the pointcloud this is only for debug visualization. Could it be possible to display it as is done with images from the node? e.g. using pcl? This would be optimal since my device may not perform well with RViz (based on readings online).

推荐答案

我最好的猜想是这样做,只是遍历cv::mat并插入pcl中以转换为味精,因为我还没有找到了直接做的任何事情.

My best guess is to do like this, and just iterate through the cv::mat and insert in the pcl to convert to msg, since I have not found anything that does directly.

#include <ros/ros.h>
// point cloud headers
#include <pcl/point_cloud.h>
//Header which contain PCL to ROS and ROS to PCL conversion functions
#include <pcl_conversions/pcl_conversions.h>
//sensor_msgs header for point cloud2
#include <sensor_msgs/PointCloud2.h>
main (int argc, char **argv)
{
    ros::init (argc, argv, "pcl_create");
    ROS_INFO("Started PCL publishing node");
    ros::NodeHandle nh;
    //Creating publisher object for point cloud
    ros::Publisher pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 1);
    //Creating a cloud object
    pcl::PointCloud<pcl::PointXYZ> cloud;
    //Creating a sensor_msg of point cloud
    sensor_msgs::PointCloud2 output;
    //Insert cloud data
    cloud.width  = 50000;
    cloud.height = 2;
    cloud.points.resize(cloud.width * cloud.height);
    //Insert random points on the clouds
    for (size_t i = 0; i < cloud.points.size (); ++i)
    {
        cloud.points[i].x = 512 * rand () / (RAND_MAX + 1.0f);
        cloud.points[i].y = 512 * rand () / (RAND_MAX + 1.0f);
        cloud.points[i].z = 512 * rand () / (RAND_MAX + 1.0f);
    }
    //Convert the cloud to ROS message
    pcl::toROSMsg(cloud, output);
    output.header.frame_id = "point_cloud";
    ros::Rate loop_rate(1);
    while (ros::ok())
    {
        //publishing point cloud data
        pcl_pub.publish(output);
        ros::spinOnce();
        loop_rate.sleep();
    }
    return 0;
}

此代码段位于批准.

这篇关于可视化Pointcloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆