-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
157 lines (139 loc) · 6.24 KB
/
main.cpp
File metadata and controls
157 lines (139 loc) · 6.24 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright (c) 2016 Baidu.com, Inc. All Rights Reserved
// @author erlangz(zhengwenchao@baidu.com)
// @date 2016/12/22 11:05:55
// @file show_point_cloud.cpp
// @brief
//
#include <iostream>
#include <sstream>
#include <string>
#include <pcl/common/common_headers.h>
#include <pcl/range_image/range_image.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/range_image_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include "3d_grid.h"
#include "features.h"
#include "types.h"
#include "label_reader.h"
using adu::perception::Box;
using adu::perception::Label;
void show_box(const Label::Ptr& label, pcl::visualization::PCLVisualizer& viewer) {
viewer.setBackgroundColor(0, 0, 0); // set background black.
for (size_t i = 0; i < label->boxes.size(); i++) {
const Box::Ptr& box = label->boxes[i];
box->show(viewer);
std::cout << "Add Box:" << box->debug_string() << std::endl;
}
};
void show_axises(pcl::visualization::PCLVisualizer& viewer) {
viewer.addCoordinateSystem(1, 0, 4, 0);
viewer.addCube(-M_PI, M_PI, 4, 70, -5.0, 3.0, 1.0, 0.0, 0.0);
}
pcl::PointCloud<pcl::PointXYZ>::Ptr read_pcd(const std::string& pcd_file_name) {
pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud(new pcl::PointCloud<pcl::PointXYZ>); //Point Cloud MonochromeCloud(pcl::PointCloud<pcl::PointXYZ>)
Eigen::Vector4f origin; //sensor acquistion origin
Eigen::Quaternionf orientation; //the sensor acquistion orientation
int file_version = 0; //file version
int offset = 0; //[input] offset, you may change this when read from tar file.
//Read Point Cloud from File
pcl::PCDReader file_reader;
int ret = file_reader.read(pcd_file_name, *point_cloud, offset);
if (ret != 0) {
std::cerr << "file:" << pcd_file_name << " open failed. ret:" << ret << std::endl;
return pcl::PointCloud<pcl::PointXYZ>::Ptr();
}
std::cout << "Open file:" << pcd_file_name << " file_version:" << file_version << std::endl;
return point_cloud;
}
void draw_point_cloud_and_bounding_box(pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud, const Label::Ptr label) {
//Show Point Cloud on the Screen
pcl::visualization::CloudViewer cloud_viewer("cloud_viewer");
//Filter Points in Box
pcl::PointIndices::Ptr all_in_boxes = pcl::PointIndices::Ptr(new pcl::PointIndices);
for (size_t i = 0; i < label->boxes.size(); i++) {
const Box::Ptr& box = label->boxes[i];
BOOST_AUTO(object, adu::perception::BoxFilter::filter(point_cloud, *box));
all_in_boxes->indices.insert(all_in_boxes->indices.end(), object->indices.begin(), object->indices.end());
}
std::cout << "Point Num:" << all_in_boxes->indices.size() << std::endl;
point_cloud = adu::perception::BoxFilter::filter(point_cloud, all_in_boxes);
cloud_viewer.showCloud(point_cloud);
cloud_viewer.runOnVisualizationThreadOnce(boost::bind(&show_box, label, _1));
while(!cloud_viewer.wasStopped()) {
}
}
void show_range_image(const pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud, float resolution) {
//-----------------------------------------------
// -----Create RangeImage from the PointCloud-----
// -----------------------------------------------
Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity());
float noise_level = 0.0;
float min_range = 0.0f;
int border_size = 1;
boost::shared_ptr<pcl::RangeImage> range_image(new pcl::RangeImage);
range_image->createFromPointCloud (*point_cloud,
pcl::deg2rad(resolution),
pcl::deg2rad(360.0f), //maxAngleWidth
pcl::deg2rad(180.0f), //maxAngleHeight
scene_sensor_pose,
pcl::RangeImage::CAMERA_FRAME,
noise_level, min_range, border_size);
// --------------------------
// -----Show range image-----
// --------------------------
pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");
range_image_widget.showRangeImage(*range_image);
range_image_widget.spinOnce();
pcl::visualization::CloudViewer cloud_viewer("cloud_viewer");
cloud_viewer.showCloud(point_cloud);
while(!cloud_viewer.wasStopped()) {
}
}
void show_cynlindrical_point_cloud(const pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud, float resolution) {
adu::perception::ThreeDimGrid<pcl::PointXYZ> grid;
grid.set_point_cloud_xyz_coord(point_cloud);
pcl::visualization::CloudViewer cloud_viewer("cylindrical_point_cloud_viewer");
cloud_viewer.runOnVisualizationThreadOnce(show_axises);
cloud_viewer.showCloud(grid.cylindrical_coord_point_cloud());
std::cout << "PointCloud:" << grid.debug_string() << std::endl;
while(!cloud_viewer.wasStopped()) {
}
}
int main(int argc, char** argv) {
std::string data_root = "/home/erlangz/3D_point_cloud/0711/original_cloud/";
//Read Cubes from File.
std::string label_file_name = "/home/erlangz/3D_point_cloud/0711/groundtruth/result.txt";
adu::perception::LabelsReader labels_reader;
if (!labels_reader.init(label_file_name)) {
std::cerr << "Open Label File:" << label_file_name << " failed." << std::endl;
return -1;
}
int NUMBER = 10;
if (argc >= 2) {
NUMBER = atoi(argv[1]);
}
float resolution = 0.23;
if (argc >= 3) {
resolution = atof(argv[2]);
}
std::cout << "Ready to Read " << NUMBER << " files." << std::endl;
adu::perception::LabelsReader::Iter iter = labels_reader.begin();
adu::perception::FeatureExtractor extractor(true, "features-");
int count = 0;
while(iter != labels_reader.end()) {
if (count++ >= NUMBER) {
break;
} else {
std::cout << "File-Count: "<< count << " ";
}
const std::string& pcd_file_name = iter->first;
const Label::Ptr label = iter->second;
pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud = read_pcd(data_root + pcd_file_name);
if (!point_cloud) { return -1; }
show_cynlindrical_point_cloud(point_cloud, resolution);
iter++;
}
return 0;
}