32 #define TEST_NAME "base/generalized_relative_pose"
49 const size_t kNumPoints = 100;
51 std::vector<Eigen::Vector3d> points3D;
52 for (
size_t i = 0; i < kNumPoints; ++i) {
53 points3D.emplace_back(RandomReal<double>(-10, 10),
54 RandomReal<double>(-10, 10),
55 RandomReal<double>(-10, 10));
58 for (
double qx = 0; qx < 0.4; qx += 0.1) {
59 for (
double tx = 0; tx < 0.5; tx += 0.1) {
60 const int kRefTform = 1;
61 const int kNumTforms = 3;
63 const std::array<SimilarityTransform3, kNumTforms> orig_tforms = {{
65 Eigen::Vector3d(tx, 0.1, 0)),
67 Eigen::Vector3d(tx, 0.2, 0)),
69 Eigen::Vector3d(tx, 0.3, 0)),
72 std::array<Eigen::Matrix3x4d, kNumTforms> rel_tforms;
73 for (
size_t i = 0; i < kNumTforms; ++i) {
74 Eigen::Vector4d rel_qvec;
75 Eigen::Vector3d rel_tvec;
77 orig_tforms[kRefTform].Translation(),
78 orig_tforms[i].Rotation(),
79 orig_tforms[i].Translation(), &rel_qvec, &rel_tvec);
84 std::vector<GR6PEstimator::X_t> points1;
85 std::vector<GR6PEstimator::Y_t> points2;
86 for (
size_t i = 0; i < points3D.size(); ++i) {
87 const Eigen::Vector3d point3D_camera1 =
88 rel_tforms[i % kNumTforms] * points3D[i].homogeneous();
89 Eigen::Vector3d point3D_camera2 = points3D[i];
90 orig_tforms[(i + 1) % kNumTforms].TransformPoint(&point3D_camera2);
92 if (point3D_camera1.z() < 0 || point3D_camera2.z() < 0) {
96 points1.emplace_back();
97 points1.back().rel_tform = rel_tforms[i % kNumTforms];
98 points1.back().xy = point3D_camera1.hnormalized();
100 points2.emplace_back();
101 points2.back().rel_tform = rel_tforms[(i + 1) % kNumTforms];
102 points2.back().xy = point3D_camera2.hnormalized();
108 const auto report = ransac.
Estimate(points1, points2);
110 BOOST_CHECK_EQUAL(report.success,
true);
112 const double matrix_diff =
113 (orig_tforms[kRefTform].Matrix().topLeftCorner<3, 4>() - report.model)
115 BOOST_CHECK_LE(matrix_diff, 1
e-2);
117 std::vector<double> residuals;
119 for (
size_t i = 0; i < residuals.size(); ++i) {
120 BOOST_CHECK_LE(residuals[i], options.
max_error);
static void Residuals(const std::vector< X_t > &points1, const std::vector< Y_t > &points2, const M_t &proj_matrix, std::vector< double > *residuals)
Report Estimate(const std::vector< typename Estimator::X_t > &X, const std::vector< typename Estimator::Y_t > &Y)
BOOST_AUTO_TEST_CASE(Estimate)
void SetPRNGSeed(unsigned seed)
void ComputeRelativePose(const Eigen::Vector4d &qvec1, const Eigen::Vector3d &tvec1, const Eigen::Vector4d &qvec2, const Eigen::Vector3d &tvec2, Eigen::Vector4d *qvec12, Eigen::Vector3d *tvec12)
Eigen::Matrix3x4d ComposeProjectionMatrix(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec)