在PCL可视化工具内打印所选点的3D坐标

时间:2017-08-21 06:41:28

标签: c++ point-cloud-library

我正在尝试使用PCL打印所选点的3D坐标。以下是代码:

#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;
}

代码编译时没有任何错误,但它不会在termainal中打印任何信息。这有什么不对?

1 个答案:

答案 0 :(得分:4)

尝试按住shift键同时左键单击以选择一个点。