码迷,mamicode.com
首页 > 编程语言 > 详细

2:C++搭配PCL显示多个点云

时间:2021-06-30 17:49:47      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:turn   sleep   typedef   add   多个   mic   types   visual   stopped   

  • 将点云显示封装为函数,在主函数里调用
 1 #pragma warning(disable:4996)
 2 #include <pcl/registration/ia_ransac.h>//采样一致性
 3 #include <pcl/point_types.h>
 4 #include <pcl/point_cloud.h>
 5 #include <pcl/features/normal_3d.h>
 6 #include <pcl/features/fpfh.h>
 7 #include <pcl/search/kdtree.h>
 8 #include <pcl/io/pcd_io.h>
 9 #include <pcl/io/ply_io.h>
10 #include <pcl/filters/voxel_grid.h>//
11 #include <pcl/filters/filter.h>//
12 #include <pcl/registration/icp.h>//icp配准
13 #include <pcl/visualization/pcl_visualizer.h>//可视化
14 #include <time.h>//时间
15 
16 using pcl::NormalEstimation;
17 using pcl::search::KdTree;
18 typedef pcl::PointXYZ PointT;
19 typedef pcl::PointCloud<PointT> PointCloud;
20 
21 //点云可视化
22 // 显示三个点云
23 void visualize_pcd(PointCloud::Ptr pcd_src, PointCloud::Ptr pcd_tgt, PointCloud::Ptr pcd_final)
24 {
25 
26     //创建初始化目标
27     pcl::visualization::PCLVisualizer viewer("registration Viewer");
28 
29     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> src_h(pcd_src, 0, 255, 0);
30     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> tgt_h(pcd_tgt, 255, 0, 0);
31     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> final_h(pcd_final, 0, 0, 255);
32     viewer.setBackgroundColor(255, 255, 255);
33     viewer.addPointCloud(pcd_src, src_h, "source cloud");
34     viewer.addPointCloud(pcd_tgt, tgt_h, "tgt cloud");
35     viewer.addPointCloud(pcd_final, final_h, "final cloud");
36 
37     while (!viewer.wasStopped())
38     {
39         viewer.spinOnce(100);
40         boost::this_thread::sleep(boost::posix_time::microseconds(100000));
41     }
42 }
43 //显示一个点云
44 void visualize_pcd1(PointCloud::Ptr pcd_src)
45 {
46 
47     //创建初始化目标
48     pcl::visualization::PCLVisualizer viewer("registration Viewer");
49 
50     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> src_h(pcd_src, 0, 255, 0);
51     viewer.setBackgroundColor(255, 255, 255);
52     viewer.addPointCloud(pcd_src, src_h, "source cloud");
53     while (!viewer.wasStopped())
54     {
55         viewer.spinOnce(100);
56         boost::this_thread::sleep(boost::posix_time::microseconds(100000));
57     }
58 }//显示两个点云
59 //显示两个点云
60 void visualize_pcd2(PointCloud::Ptr pcd_src, PointCloud::Ptr pcd_tgt)
61 {
62 
63     //创建初始化目标
64     pcl::visualization::PCLVisualizer viewer("registration Viewer");
65 
66     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> src_h(pcd_src, 0, 255, 0);
67     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> tgt_h(pcd_tgt, 255, 0, 0);
68     viewer.setBackgroundColor(255, 255, 255);
69     viewer.addPointCloud(pcd_src, src_h, "source cloud");
70     viewer.addPointCloud(pcd_tgt, tgt_h, "tgt cloud");
71 
72     while (!viewer.wasStopped())
73     {
74         viewer.spinOnce(100);
75         boost::this_thread::sleep(boost::posix_time::microseconds(100000));
76     }
77 }
78 int main(int argc, char** argv)
79 {
80 
81     //加载点云文件
82     PointCloud::Ptr test1(new PointCloud);//定义点云1
83     pcl::io::loadPLYFile("bun000.ply", *test1);//g
84     PointCloud::Ptr test2(new PointCloud);//定义点云2
85     pcl::io::loadPLYFile("bun045.ply", *test2);//r
86     PointCloud::Ptr test3(new PointCloud);//定义点云3
87     pcl::io::loadPLYFile("bun090.ply", *test3);//g
88 
89 
90     visualize_pcd(test1, test2, test3);//显示三个
91     //visualize_pcd2(test1, test2);//显示两个
92     //visualize_pcd1(test1);//显示一个
93     return (0);
94 }

技术图片

 

2:C++搭配PCL显示多个点云

标签:turn   sleep   typedef   add   多个   mic   types   visual   stopped   

原文地址:https://www.cnblogs.com/beautifulmoonlight/p/14951683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!