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

Print 3D coordinates of the selected point inside PCL visualizer

本文关键字:3D 坐标 打印 PCL 可视化 工具      更新时间:2023-10-16

我正在尝试使用 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 打印任何信息。这是怎么回事?

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