标签:clicked viewer args PCL1.8 points 可视化 pcl 点云 cloud
基于PCL1.8点云可视化交互|CSDN创作打卡
1、点云可视化
基于点云库PCL1.8,实现了点云的显示,按住Shfit+鼠标左键选择点,能显示出点的坐标。
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
using namespace pcl;
typedef pcl::PointXYZ PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
// Mutex: //进程锁
boost::mutex cloud_mutex;
//用于给回调函数的结构体定义
struct callback_args
{
PointCloudT::Ptr clicked_points_3d;
pcl::visualization::PCLVisualizer::Ptr viewerPtr;
};
//回调函数
//按住shift,鼠标右键点一下点云,会显示出点的距离
void pp_callback(const pcl::visualization::PointPickingEvent& event, void* args)
{
struct callback_args* data = (struct callback_args*)args;
if (event.getPointIndex() == -1)
return;
PointT current_point;
event.getPoint(current_point.x, current_point.y, current_point.z);
data->clicked_points_3d->clear();//将上次选的点清空
data->clicked_points_3d->points.push_back(current_point);//添加新选择的点
// Draw clicked points in red:将选中点用红色标记
pcl::visualization::PointCloudColorHandlerCustom<PointT> red(data->clicked_points_3d, 255, 0, 0);
data->viewerPtr->removePointCloud("clicked_points");
data->viewerPtr->addPointCloud(data->clicked_points_3d, red, "clicked_points");
data->viewerPtr->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 10, "clicked_points");
std::cout << current_point.x << " " << current_point.y << " " << current_point.z << std::endl;
}
int main()
{
std::string incloudfile = "rabbit.pcd";
PointCloud<PointXYZ>::Ptr cloud(new PointCloud<PointXYZ>);
boost::shared_ptr<visualization::PCLVisualizer> viewer(new visualization::PCLVisualizer("3D viewer")); // 实例化PCLVisualizer对象,窗口命名为3D viewer
pcl::io::loadPCDFile(incloudfile, *cloud);
viewer->setBackgroundColor(0, 0, 0); // 设置背景颜色
viewer->addPointCloud<PointXYZ>(cloud, "sample cloud");
//viewer->setPointCloudRenderingProperties(visualization::PCL_VISUALIZER_OPACITY, 2, "sample cloud");// 设置点云显示属性,
cloud_mutex.lock();
//可视化窗口执行回调函数
struct callback_args cb_args;
PointCloudT::Ptr clicked_points_3d(new PointCloudT);
cb_args.clicked_points_3d = clicked_points_3d;
cb_args.viewerPtr = pcl::visualization::PCLVisualizer::Ptr(viewer);
//注册屏幕选点事件
viewer->registerPointPickingCallback(pp_callback, (void*)&cb_args);
//Shfit+鼠标左键选择点
std::cout << "Shift+click on three floor points, then press 'Q'..." << std::endl;
// Spin until 'Q' is pressed:
//摁“Q”键结束
viewer->spin();
//释放互斥体
cloud_mutex.unlock();
while (!viewer->wasStopped()) {
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
return 0;
}
标签:clicked,viewer,args,PCL1.8,points,可视化,pcl,点云,cloud 来源: https://blog.csdn.net/qq_44733143/article/details/122788888
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。