AIBluefisher / GraphOptim

The official implementation of our CVPR 2021 paper - Hybrid Rotation Averaging: A Fast and Robust Rotation Averaging Approach
BSD 3-Clause "New" or "Revised" License
147 stars 24 forks source link

How can I use this library to compute output files from colmap? #7

Closed Devincool closed 2 years ago

Devincool commented 2 years ago

If the g2o file can generated from colmap? Please add some examples. Thank you!

AIBluefisher commented 2 years ago

Sure. But seems COLMAP doesn't store the relative camera poses in the database currently. You may try my branch instead: https://github.com/AIBluefisher/DAGSfM. For the conversion from COLMAP to g2o, you just need to extract the camera poses from the images, just notice that COLMAP stores the quaternion into vectors in the form of [qw, qx, qy, qz]. You may refer to this line of code for g2o's format. You may see the sample code below:

  Database database(database_path);
  std::ifstream ofs(g2o_filename);

  std::vector<TwoViewGeometry> two_view_geometries;
  std::vector<image_pair_t> image_pair_ids;
  database.ReadTwoViewGeometries(&image_pair_ids, &two_view_geometries);

  for (uint i = 0; i < image_pairs.size(); i++) {
    const image_t image_id1 = image_pairs[i].first,
                  image_id2 = image_pairs[i].second;
    const ImagePair view_id_pair = ImagePair(image_id1, image_id2);
    const TwoViewGeometry& two_view_geometry = two_view_geometries[I];
    const Eigen::Vector4d& tvec = two_view_geometry.tvec();
    const Eigen::Vector4d& qvec = two_view_geometry.qvec();
    ifs << image_id1 << " " << image_id2 << " " << tvec[0] << " " << tvec[1] << " " << tvec[2] << qvec[1] << " " << qvec[2] << " " 
        << qvec[3] << " " << qvec[0] << ....... << std::endl;
  }
  ifs.close();

Of course, the qvec should follow by the 6*6 covariance matrix(actually only half entries are needed). If they are not known, just fill zeros as placeholders.

Devincool commented 2 years ago

Thanks for reply!