Example #1
0
void main()
{
    // viewerを作る
    pcl::visualization::CloudViewer viewer( "OpenNI Viewer" );

    // データ更新のコールバック関数
    boost::function<void (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr&)> f = 
        [&viewer](const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud) {
            if (!viewer.wasStopped()) {
                pcl::PointCloud<pcl::PointXYZRGB> segmented_cloud( *cloud );
                segmentate( segmented_cloud, 0.01 );
                viewer.showCloud( segmented_cloud.makeShared() );
            }
    };

    // OpenNIの入力を作る
    pcl::Grabber* interface = new pcl::OpenNIGrabber();
    interface->registerCallback( f );
    interface->start();
    while ( !viewer.wasStopped() ) {
        Sleep( 0 );
    }

    interface->stop();
}
Example #2
0
int  main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr1(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr segmented_cloud(new pcl::PointCloud<pcl::PointXYZ>);
//load point cloud
loadcloud(cloud_ptr);

pcl::PointCloud <pcl::Normal>::Ptr normals(new pcl::PointCloud <pcl::Normal>);

//calculate the normal of the point cloud.
NormalCalculation(cloud_ptr,normals);
//display point cloud.
displaycloud(cloud_ptr);
//display the normal of the point cloud.
displayNormal(cloud_ptr, normals);
//segmentation by region growing method.
segmented_cloud=RegionGrowingSegmentation(cloud_ptr,normals);
//display the segmented the cloud.
displaycloud(segmented_cloud);
return 0;

}
Example #3
0
 void EuclideanClustering::computeCentroidsOfClusters(
   Vector4fVector& ret,
   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
   std::vector<pcl::PointIndices> cluster_indices)
 {
   pcl::ExtractIndices<pcl::PointXYZ> extract;
   extract.setInputCloud(cloud);
   ret.resize(cluster_indices.size());
   for (size_t i = 0; i < cluster_indices.size(); i++)
   {
     // build pointcloud
     pcl::PointCloud<pcl::PointXYZ>::Ptr segmented_cloud (new pcl::PointCloud<pcl::PointXYZ>);
     pcl::PointIndices::Ptr segmented_indices (new pcl::PointIndices);
     for (size_t j = 0; j < cluster_indices[i].indices.size(); j++)
     {
       segmented_indices->indices.push_back(cluster_indices[i].indices[j]);
     }
     extract.setIndices(segmented_indices);
     extract.filter(*segmented_cloud);
     Eigen::Vector4f center;
     pcl::compute3DCentroid(*segmented_cloud, center);
     ret[i] = center;
   }
 }