9:C++搭配PCL降维将点云投影至平面

代码:

 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/filters/voxel_grid.h>//
10 #include <pcl/filters/filter.h>//
11 #include <pcl/registration/icp.h>//icp配准
12 #include <pcl/visualization/pcl_visualizer.h>//可视化
13 #include <time.h>//时间
14 #include <math.h>
15 #include <vector>
16 
17 using namespace std;
18 using pcl::NormalEstimation;
19 using pcl::search::KdTree;
20 typedef pcl::PointXYZ PointT;
21 typedef pcl::PointCloud<PointT> PointCloud;
22 
23 void visualize_pcd2(PointCloud::Ptr pcd_src, PointCloud::Ptr pcd_tgt)
24 {
25 
26     //创建初始化目标
27     pcl::visualization::PCLVisualizer viewer("registration Viewer");
28     int v1(0);
29     int v2(1);
30     viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
31     viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
32     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> src_h(pcd_src, 255, 0, 0);
33     pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> tgt_h(pcd_tgt, 0, 255, 0);
34     viewer.setBackgroundColor(255, 255, 255);
35     viewer.addPointCloud(pcd_src, src_h, "source cloud", v1);
36     viewer.addPointCloud(pcd_tgt, tgt_h, "tgt cloud", v2);
37     while (!viewer.wasStopped())
38     {
39         viewer.spinOnce(100);
40         boost::this_thread::sleep(boost::posix_time::microseconds(100000));
41     }
42 }
43 
44 int main() 
45 {
46 
47     //1加载点云文件
48     PointCloud::Ptr cloud_src(new PointCloud);//原点云,待配准
49     PointCloud::Ptr cloud_src2(new PointCloud);//原点云,待配准
50     pcl::io::loadPCDFile("demo_bun000_z.pcd", *cloud_src);//g
51     pcl::io::loadPCDFile("bun000_transxzy2_z.pcd", *cloud_src2);//g
52     
53 
54     for (size_t i = 0; i < cloud_src->points.size(); ++i)
55     {
56         cloud_src->points[i].y =0;
57     }
58     for (size_t j = 0; j < cloud_src2->points.size(); ++j)
59     {
60         cloud_src2->points[j].y = 0;
61     }
62     pcl::io::savePCDFile("demo_bun000_z.pcd", *cloud_src);//g
63     pcl::io::savePCDFile("demo_bun000xy_z.pcd", *cloud_src2);//g
64 
65     //可视化
66     visualize_pcd2(cloud_src, cloud_src2);
67     return (0);
68 
69 
70 
71 }

 

上一篇:vue 放大图片查看,缩放等v-viewer


下一篇:BigData File Viewer工具介绍