Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print 3D coordinates of the selected point inside PCL visualizer

I am trying to print the 3D coordinates of the selected point using PCL. Below is the code:

#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>

using namespace std;

void pointPickingEventOccurred (const pcl::visualization::PointPickingEvent& event, void* viewer_void)
{
  std::cout << "[INOF] Point picking event occurred." << std::endl;

  float x, y, z;
  if (event.getPointIndex () == -1)
  {
     return;
  }
  event.getPoint(x, y, z);
  std::cout << "[INOF] Point coordinate ( " << x << ", " << y << ", " << z << ")" << std::endl;
}

int main (int argc, char** argv)
{
    pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile ("body.pcd", *body);
    viewer.addPointCloud (body,"body");
    viewer.registerPointPickingCallback (pointPickingEventOccurred, (void*)&viewer);
    viewer.spin();
    return 0;
}

The code compiles without any error but it doesn't print any information in termainal. What's wrong here?

like image 472
Ravi Joshi Avatar asked Aug 21 '17 06:08

Ravi Joshi


1 Answers

Try holding down shift while left-clicking to pick a point.

like image 59
shouston Avatar answered Oct 21 '22 17:10

shouston