Update viewer to display a cluster

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Update viewer to display a cluster

soichiru
Hello I have a issue about displaying only one cluster after processing a the input cloud, in fact I am getting the input cloud from a xtion camera, but as the program is running if there is a small change in the camera position or the object position in front of the camera, I see the new cluster in the new position but also I can see the old cluster and it continues. Part of the code is something like this:
int main {
...
...

 pcl::Grabber* interface = new pcl::OpenNIGrabber();
 boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
 boost::bind (&cloud_cb_, _1, cloud, &new_cloud_available_flag);
 interface->registerCallback (f); // Error in this part
 interface->start ();

 pcl::visualization::PCLVisualizer viewer("PCL Viewer");          // viewer initialization
 viewer.setCameraPosition(0,0,-2,0,-1,0,0);

while (!viewer.wasStopped()){
....
...
 std::vector<pcl::PointIndices> cluster_indices;
typename pcl::search::KdTree<PointT>::Ptr tree (new pcl::search::KdTree<PointT>);
tree->setInputCloud(cloud);
pcl::EuclideanClusterExtraction<PointT> ec;
ec.setClusterTolerance(2 * 0.06);
ec.setMinClusterSize(min_points);
ec.setMaxClusterSize(max_points);
ec.setSearchMethod(tree);
ec.setInputCloud(cloud);
ec.extract(cluster_indices);
....
....
viewer.removeAllPointClouds();
viewer.removeAllShapes();
pcl::visualization::PointCloudColorHandlerRGBField<PointT> rgb(current_points);
viewer.addPointCloud<PointT> (current_points, rgb, "input_cloud");
...
...
viewer.spinOnce();

} // End while loop

}

So I don't know if is right what I'm doing, or I'm missing something else.
If is necessary something more to be clear please let me know.

And I hope someone could help me.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Update viewer to display a cluster

VictorLamoine
Administrator
Hello,

You code does not expose how current_points is filled.
Make sure it is clear before appending points to it, otherwise you might end up with part of the last cloud.

Bye