Write projection matrix P = K * [R t] to file and prepend given header.
| 64 | |
| 65 | // Write projection matrix P = K * [R t] to file and prepend given header. |
| 66 | void WriteProjectionMatrix(const std::filesystem::path& path, |
| 67 | const Camera& camera, |
| 68 | const Image& image, |
| 69 | const std::string& header) { |
| 70 | THROW_CHECK(camera.model_id == PinholeCameraModel::model_id); |
| 71 | |
| 72 | std::ofstream file(path, std::ios::trunc); |
| 73 | THROW_CHECK_FILE_OPEN(file, path); |
| 74 | file.imbue(std::locale::classic()); |
| 75 | |
| 76 | Eigen::Matrix3d calib_matrix = Eigen::Matrix3d::Identity(); |
| 77 | calib_matrix(0, 0) = camera.FocalLengthX(); |
| 78 | calib_matrix(1, 1) = camera.FocalLengthY(); |
| 79 | calib_matrix(0, 2) = camera.PrincipalPointX(); |
| 80 | calib_matrix(1, 2) = camera.PrincipalPointY(); |
| 81 | |
| 82 | const Eigen::Matrix3x4d img_from_world = |
| 83 | calib_matrix * image.CamFromWorld().ToMatrix(); |
| 84 | |
| 85 | if (!header.empty()) { |
| 86 | file << header << '\n'; |
| 87 | } |
| 88 | |
| 89 | WriteMatrix(img_from_world, &file); |
| 90 | } |
| 91 | |
| 92 | void WriteCOLMAPCommands(const bool geometric, |
| 93 | const std::filesystem::path& workspace_path, |
no test coverage detected