【C++】pose文件保存,结构化文件保存

1. pose文件保存,结构化文件保存

void Algorithm::Callback(
    const cv::Mat &img0, const cv::Mat &img1, const TimeStampNs t) {
    
    

  std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(8);
  double time_stamp = polaris_->getLastFrames()->getMinTimestampSeconds();
  const Transformation &T_w_b = polaris_->getLastFrames()->get_T_W_B();
  Eigen::Vector3d p = T_w_b.getPosition();
  const Eigen::Quaterniond &q = T_w_b.getRotation().toImplementation();

  static bool flag_filename = true;
  static std::string filename = "";
  if (flag_filename) {
    
    
    time_t now = time(0);
    tm *local_time = localtime(&now);
    char time_str[100];
    strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H_%M_%S", local_time);
    filename = "/home/sun/build/pose_" + std::string(time_str) + ".txt";
    flag_filename = false;
  }

  std::string filename1 ="/home/sun/build/pose.txt";
  std::ofstream out_pos(filename, std::ios::out | std::ios::app);
  if (out_pos.is_open()) {
    
    
    out_pos << std::setiosflags(std::ios::fixed) << time_stamp << " " << p[0] << " " << p[1] << " "
            << p[2] << " " << q.x() << " " << q.y() << " " << q.z() << " " << q.w() << std::endl;
  }
}

猜你喜欢

转载自blog.csdn.net/Darlingqiang/article/details/132711707