pointcloud.cpp 1.69 KB
#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;
}