T_j_i @ (T_w_i)^-1 @ T_w_j = I
| 9 | |
| 10 | // T_j_i @ (T_w_i)^-1 @ T_w_j = I |
| 11 | class RelativePoseError { |
| 12 | public: |
| 13 | RelativePoseError(const Eigen::Matrix4d& relative_pose, Eigen::Vector3d translation_weight, Eigen::Vector3d rotation_weight) |
| 14 | : relative_j_i_translation_(Eigen::Vector3d::Zero()), relative_j_i_rotation_lie_algebra_(Eigen::Vector3d::Zero()), translation_weight_(translation_weight), rotation_weight_(rotation_weight) { |
| 15 | relative_j_i_translation_ = relative_pose.block<3, 1>(0, 3); |
| 16 | Eigen::Matrix<double, 3, 3> relative_j_i_rotation = relative_pose.block<3, 3>(0, 0); |
| 17 | ceres::RotationMatrixToAngleAxis(relative_j_i_rotation.data(), relative_j_i_rotation_lie_algebra_.data()); |
| 18 | } |
| 19 | template<typename T> |
| 20 | bool operator()(const T* camera_i, const T* camera_j, T* residuals) const { |
| 21 | using TMatrix3 = Eigen::Matrix<T, 3, 3>; |
| 22 | using TVector3 = Eigen::Matrix<T, 3, 1>; |
| 23 | TVector3 translation_i = Eigen::Map<const TVector3>(camera_i); |
| 24 | TVector3 rotation_i = Eigen::Map<const TVector3>(camera_i + 3); |
| 25 | TVector3 translation_j = Eigen::Map<const TVector3>(camera_j); |
| 26 | TVector3 rotation_j = Eigen::Map<const TVector3>(camera_j + 3); |
| 27 | TMatrix3 R_i; |
| 28 | ceres::AngleAxisToRotationMatrix(rotation_i.data(), R_i.data()); |
| 29 | TMatrix3 R_j; |
| 30 | ceres::AngleAxisToRotationMatrix(rotation_j.data(), R_j.data()); |
| 31 | TMatrix3 relative_j_i_rotation; |
| 32 | TVector3 relative_j_i_rotation_lie_algebra_T = relative_j_i_rotation_lie_algebra_.cast<T>(); |
| 33 | ceres::AngleAxisToRotationMatrix(relative_j_i_rotation_lie_algebra_T.data(), relative_j_i_rotation.data()); |
| 34 | TMatrix3 rotation_loss = relative_j_i_rotation * R_i.transpose() * R_j; |
| 35 | ceres::RotationMatrixToAngleAxis(rotation_loss.data(), residuals + 3); |
| 36 | Eigen::Map<TVector3> rotation_residuals_map(residuals + 3); |
| 37 | rotation_residuals_map = rotation_weight_.cast<T>().asDiagonal() * rotation_residuals_map; |
| 38 | TVector3 translation_residuals = relative_j_i_rotation * R_i.transpose() * (translation_j - translation_i) + relative_j_i_translation_; |
| 39 | Eigen::Map<TVector3> translation_residuals_map(residuals); |
| 40 | translation_residuals_map = translation_weight_.cast<T>().asDiagonal() * translation_residuals; |
| 41 | return true; |
| 42 | } |
| 43 | Eigen::Vector3d relative_j_i_translation_; |
| 44 | Eigen::Vector3d relative_j_i_rotation_lie_algebra_; |
| 45 | Eigen::Vector3d translation_weight_; |
| 46 | Eigen::Vector3d rotation_weight_; |
| 47 | }; |
| 48 | |
| 49 | std::unordered_map<int64_t, py::array_t<double>> pose_graph_solve( |
| 50 | std::unordered_map<int64_t, py::array_t<double>> camera_poses, |
nothing calls this directly
no outgoing calls
no test coverage detected