#include #include #include #include #include #include #include #include #include #include #include "o3d3xx_camera.h" #include "o3d3xx_framegrabber.h" #include "o3d3xx_image.h" using namespace std; int main (int argc, char** argv) { //logging method o3d3xx::Logging::Init(); //initialise camera constructor expects IP address o3d3xx::Camera::Ptr cam = std::make_shared("192.168.1.69"); //create buffer to fetch image o3d3xx::ImageBuffer::Ptr img = std::make_shared(); //framegrabber o3d3xx::FrameGrabber::Ptr fg = std::make_shared( cam, o3d3xx::IMG_AMP|o3d3xx::IMG_RDIS|o3d3xx::IMG_CART); //get frame from camera if (! fg->WaitForFrame(img.get(), 2000)) { std::cerr << "Timeout waiting for camera!" << std::endl; return -1; } pcl::PCDWriter writer; pcl::PointCloud::Ptr cloud (new pcl::PointCloud); pcl::PointCloud::Ptr cloudIn (new pcl::PointCloud); cloudIn = img->Cloud(); writer.write("region_growing_tutorial.pcd", *cloudIn, false); if ( pcl::io::loadPCDFile ("region_growing_tutorial.pcd", *cloud) == -1) { std::cout << "Cloud reading failed." << std::endl; return (-1); } vector temp; pcl::removeNaNFromPointCloud(*cloud,*cloud, temp); cout << temp.size() << endl; cout << cloud->size() << endl; pcl::search::Search::Ptr tree = boost::shared_ptr > (new pcl::search::KdTree); pcl::PointCloud ::Ptr normals (new pcl::PointCloud ); pcl::NormalEstimation normal_estimator; normal_estimator.setSearchMethod (tree); normal_estimator.setInputCloud (cloud); normal_estimator.setKSearch (50); normal_estimator.compute (*normals); pcl::IndicesPtr indices (new std::vector ); pcl::PassThrough pass; pass.setInputCloud (cloud); pass.setFilterFieldName ("z"); pass.setFilterLimits (0.0, 1.0); pass.filter (*indices); pcl::RegionGrowing reg; reg.setMinClusterSize (50); reg.setMaxClusterSize (1000000); reg.setSearchMethod (tree); reg.setNumberOfNeighbours (30); reg.setInputCloud (cloud); //reg.setIndices (indices); reg.setInputNormals (normals); reg.setSmoothnessThreshold (3.0 / 180.0 * M_PI);// graden naar radial reg.setCurvatureThreshold (1.0); std::vector clusters; reg.extract (clusters); std::cout << "Number of clusters is equal to " << clusters.size () << std::endl; std::cout << "First cluster has " << clusters[0].indices.size () << " points." << endl; std::cout << "These are the indices of the points of the initial" << std::endl << "cloud that belong to the first cluster:" << std::endl; int counter = 0; while (counter < clusters[0].indices.size ()) { std::cout << clusters[0].indices[counter] << ", "; counter++; if (counter % 10 == 0) std::cout << std::endl; } std::cout << std::endl; pcl::PointCloud ::Ptr colored_cloud = reg.getColoredCloud (); pcl::visualization::PCLVisualizer viewer ("Cluster viewer"); viewer.addPointCloud(colored_cloud,"cloud"); //viewer.addPointCloudNormals(colored_cloud, normals, 10, 0.05, "normals",0); while (!viewer.wasStopped ()) { viewer.spinOnce(100); } return (0); }