Visualize pointcloud

前端 未结 1 1802
情话喂你
情话喂你 2021-01-18 04:04

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

How do I Convert the found pointcloud from

相关标签:
1条回答
  • 2021-01-18 04:43

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

    This code snippet was found at apprize.

    0 讨论(0)
提交回复
热议问题