pointcloud.cpp
1.69 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
#include "common.h"
#include "cv_func.h"
#include "pcl_func.h"
/*
[input]
argc = 2
argv[0] = program
argv[1] = depth folder (containing depth images)
[output]
single frame depth image & point cloud
average depth image & point cloud
*/
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cout << "[Error] Program Usage: [./cloud] [depth image folder]" << std::endl;
return -1;
}
//intrinsic setup
camInfo cam;
realsenseSetUp(cam);
std::cout << "[Processing] Intrinsic parameters for Realsense setting done..." << std::endl;
//get raw, filtered img
std::string folderPath = argv[1];
std::vector<cv::Mat> depths;
readFolder(folderPath, depths);
cv::Mat meanImg = getMeanImg(depths);
cv::Mat filtered = medianFilter(meanImg);
cv::Mat raw = depths[0];
std::cout << "[Processing] image filtering done..." << std::endl;
//3D reconstruction
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_original(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
reconstruction3D(cam, raw, cloud_original);
reconstruction3D(cam, filtered, cloud_filtered);
std::cout << "[Processing] 3d reconstruction done..." << std::endl;
//create output folder
std::size_t div = folderPath.find_last_of("/\\");
std::string outputPath = folderPath.substr(0, div + 1) + "result";
path p(outputPath);
create_directory(p);
//save output
pcl::io::savePCDFile(outputPath + "/cloud_original.pcd", *cloud_original);
pcl::io::savePCDFile(outputPath + "/cloud_filtered.pcd", *cloud_filtered);
cv::imwrite(outputPath + "/img_original.png", raw);
cv::imwrite(outputPath + "/img_filtered.png", filtered);
return 0;
}