-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (77 loc) · 2.9 KB
/
Copy pathmain.cpp
File metadata and controls
84 lines (77 loc) · 2.9 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright
#include <pcl/console/time.h>
#include <pcl/io/ply_io.h>
#include "ClusteringAlgo.hpp"
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " pointcloud.ply" << std::endl;
return -1;
}
// 读取点云
PointCloudT cloud(new PointCloud);
if (pcl::io::loadPCDFile(argv[1], *cloud) == -1) {
std::cout << "Load pointcloud " << argv[1] << " failed." << std::endl;
return -1;
}
// start pcl::EuclideanClusterExtraction
std::cout << "Start pcl::EuclideanClusterExtraction ----------------------" << std::endl;
pcl::console::TicToc tt;
tt.tic();
// 聚类
auto clusters = ClusterEuclideanCluster(cloud, 0.1);
tt.toc();
std::cout << "Found " << clusters.size() << " clusters." << std::endl;
// extract pointcloud from clusters and assign different color to each class
pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
int cluster_id = 1;
for (auto &cluster : clusters) {
for (auto &index : cluster.indices) {
pcl::PointXYZRGB point;
point.x = cloud->points[index].x;
point.y = cloud->points[index].y;
point.z = cloud->points[index].z;
point.r = 255 * (cluster_id % 2);
point.g = 255 * (cluster_id % 3);
point.b = 255 * (cluster_id % 5);
colored_cloud->push_back(point);
}
cluster_id++;
}
// save colored pointcloud
pcl::io::savePCDFileBinary("euclidean_cluster_colored.pcd", *colored_cloud);
std::cout << "Saved " << colored_cloud->size()
<< " data points to euclidean_cluster_colored.ply." << std::endl;
std::cout << "Done in " << tt.toc() << " ms." << std::endl;
std::cout << "Done pcl::EuclideanClusterExtraction ----------------------" << std::endl;
// start FastEuclideanClustering
std::cout << "Start FastEuclideanClustering ----------------------" << std::endl;
tt.tic();
clusters.clear();
clusters = ClusterFEC(cloud, 0.1);
tt.toc();
std::cout << "Found " << clusters.size() << " clusters." << std::endl;
// extract pointcloud from clusters and assign different color to each class
colored_cloud->clear();
cluster_id = 1;
for (auto &cluster : clusters) {
for (auto &index : cluster.indices) {
pcl::PointXYZRGB point;
point.x = cloud->points[index].x;
point.y = cloud->points[index].y;
point.z = cloud->points[index].z;
point.r = 255 * (cluster_id % 2);
point.g = 255 * (cluster_id % 3);
point.b = 255 * (cluster_id % 5);
colored_cloud->push_back(point);
}
cluster_id++;
}
// save colored pointcloud
pcl::io::savePCDFileBinary("fec_cluster_colored.pcd", *colored_cloud);
std::cout << "Saved " << colored_cloud->size()
<< " data points to fec_cluster_colored.ply." << std::endl;
std::cout << "Done in " << tt.toc() << " ms." << std::endl;
std::cout << "Done FastEuclideanCluster ----------------------" << std::endl;
return 0;
}