pcl

487 words

配置pcl+vs环境

  • 配置pcl环境出现的问题
    运行D:\PCL 1.12.0\PCL 1.14.0\bin>pcl_mesh_sampling.exe D:\solidworks D:\solidworks时 系统错误:由于找不到vtk
    未解决。反复检查了环境。改用cloudcompare。
    -vs报错C1083无法打开源文件: “_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fox64\Debug\ /Fdx64\Debug\vc143.pdb /external:W3 /Gd /TP /FC /errorReport:prompt 1.cpp”: No such file or directory pcltest D:_SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING \D _UNICODE \D UNICODE \Gm- \EHsc \RTC1 \MDd \GS \fp:precise \Zc:wchar_t \Zc:forScope \Zc:inline \permissive- \Fox64\Debug\ \Fdx64\Debug\vc143.pdb \external:W3 \Gd \TP \FC \errorReport:prompt 1.cpp 1
    SDK版本移位
  • 默认release模式也有原因 运行代码在debug模式下(闲鱼配置环境两小时花费45)

使用solidworks建模

建模T形接头、搭接接头和对接接头等焊缝类型,并使用cloudcompare将文件转换为pcd格式的3D点云。

  • 添加噪声

segmentation分割(聚类)

大部分代码来源于pcl官方教程,仅作少量修改,作练习用。

实现效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/filters/filter_indices.h> // for pcl::removeNaNFromPointCloud
#include <pcl/segmentation/region_growing.h>

int
main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile <pcl::PointXYZ>("T.pcd", *cloud) == -1)
{
std::cout << "Cloud reading failed." << std::endl;
return (-1);
}

pcl::search::Search<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
pcl::PointCloud <pcl::Normal>::Ptr normals(new pcl::PointCloud <pcl::Normal>);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimator;
normal_estimator.setSearchMethod(tree);
normal_estimator.setInputCloud(cloud);
normal_estimator.setKSearch(50);
normal_estimator.compute(*normals);

pcl::IndicesPtr indices(new std::vector <int>);
pcl::removeNaNFromPointCloud(*cloud, *indices);

pcl::RegionGrowing<pcl::PointXYZ, pcl::Normal> reg;
reg.setMinClusterSize(50);
reg.setMaxClusterSize(1000000);
reg.setSearchMethod(tree);
reg.setNumberOfNeighbours(30);
reg.setInputCloud(cloud);
reg.setIndices(indices);
reg.setInputNormals(normals);
reg.setSmoothnessThreshold(3.0 / 180.0 * M_PI);
reg.setCurvatureThreshold(1.0);

std::vector <pcl::PointIndices> clusters;
reg.extract(clusters);

std::cout << "Number of clusters is equal to " << clusters.size() << std::endl;
std::cout << "First cluster has " << clusters[0].indices.size() << " points." << std::endl;
std::cout << "These are the indices of the points of the initial" <<
std::endl << "cloud that belong to the first cluster:" << std::endl;
std::size_t counter = 0;
while (counter < clusters[0].indices.size())
{
std::cout << clusters[0].indices[counter] << ", ";
counter++;
if (counter % 10 == 0)
std::cout << std::endl;
}
std::cout << std::endl;

pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud();
pcl::visualization::CloudViewer viewer("Cluster viewer");
viewer.showCloud(colored_cloud);
while (!viewer.wasStopped())
{
}

return (0);
}
Comments