1
votes

I am doing a project for the university and I need to extract the point cloud of the people to work with it. I made an ROS node adapting the code of the tutorial Ground based rgdb people detection, and now I want to publish in a topic the point cloud of the first detected cluster.

But I am not able to extract that point cloud, the definition of the class is defined here person_cluster.h. And there is a public member:

typedef pcl::PointCloud<PointT> PointCloud;

So to convert it in a sensor_msgs::PointCloud2 I do:

pcl_conversions::fromPCL(clusters.at(0).PointCloud,person_msg);

where person_msg is the PointCLoud2 message, clusters is a vector of pcl::people::PersonCluster<PointT>, and I want to publish only the first point cloud because I assume that there is only one person in the scene.

The compiler gives me this error:

error: invalid use of ‘pcl::people::PersonCluster::PointCloud’ pcl_conversions::fromPCL(clusters.at(0).PointCloud,person_msg);

I don't have a lot of knowledge about C++ and I am not able to overcome this error. Googling that error it seems that it appears when you don't "define" well a class, but I doubt that in the pcl library they defined bad a class.

1

1 Answers

0
votes

For those that are interested I resolved my problem.

In the forum of pcl I found a post where the same developer of the people detector I used gave the answer. So basically:

// Get cloud after voxeling and ground plane removal:
      PointCloudT::Ptr no_ground_cloud (new PointCloudT);
      no_ground_cloud = people_detector.getNoGroundCloud();

      // Show pointclouds of every person cluster:
      PointCloudT::Ptr cluster_cloud (new PointCloudT);
      for(std::vector<pcl::people::PersonCluster<PointT> >::iterator it = clusters.begin(); it != clusters.end(); ++it)
      {
        if (it->getPersonConfidence() > min_confidence)
        {
          // Create the pointcloud with points belonging to the current cluster:
          cluster_cloud->clear();
          pcl::PointIndices clusterIndices = it->getIndices();    // cluster indices
          std::vector<int> indices = clusterIndices.indices;
          for(unsigned int i = 0; i < indices.size(); i++)        // fill cluster cloud
          {
            PointT* p = &no_ground_cloud->points[indices[i]];
            cluster_cloud->push_back(*p);
          }

          // Visualization:
          viewer.removeAllPointClouds();
          viewer.removeAllShapes();
          pcl::visualization::PointCloudColorHandlerRGBField<PointT> rgb(cluster_cloud);
          viewer.addPointCloud<PointT> (cluster_cloud, rgb, "cluster_cloud");
          viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "cluster_cloud");
          viewer.spinOnce(500);
        }
      }

Actually I was not able to convert such type of point cloud in a sensor message PointCloud2, even trying to convert that pointcloud in a pcl::PointCloud<pcl::PointXYZ>.

A working solution was that to use as cluster_cloud a type of pcl::PointCloud<pcl::PointXYZ> and then using a publisher of type pcl::PointCloud<pcl::PointXYZ> Such:

ros::Publisher person_pub = nh.advertise<PointCloud>("personPointCloud", 1000);

Anyway it was no publish anything, the rviz didnt showed anything. But the viever was displaying the point cloud of the detected person. Since that pointcloud was not such I expected (if you move the arm the algorithm does no give you all the arm) it is not useful for my project so I drop it.

So still remains the problem to publish it in ros, but the problem to get the pointcloud is resolved.