32 #define TEST_NAME "base/generalized_absolute_pose"
51 std::vector<Eigen::Vector3d> points3D;
52 points3D.emplace_back(1, 1, 1);
53 points3D.emplace_back(0, 1, 1);
54 points3D.emplace_back(3, 1.0, 4);
55 points3D.emplace_back(3, 1.1, 4);
56 points3D.emplace_back(3, 1.2, 4);
57 points3D.emplace_back(3, 1.3, 4);
58 points3D.emplace_back(3, 1.4, 4);
59 points3D.emplace_back(2, 1, 7);
61 auto points3D_faulty = points3D;
62 for (
size_t i = 0; i < points3D.size(); ++i) {
63 points3D_faulty[i](0) = 20;
66 for (
double qx = 0; qx < 1; qx += 0.2) {
67 for (
double tx = 0; tx < 1; tx += 0.1) {
68 const int kRefTform = 1;
69 const int kNumTforms = 3;
71 const std::array<SimilarityTransform3, kNumTforms> orig_tforms = {{
73 Eigen::Vector3d(tx, -0.1, 0)),
75 Eigen::Vector3d(tx, 0, 0)),
77 Eigen::Vector3d(tx, 0.1, 0)),
80 std::array<Eigen::Matrix3x4d, kNumTforms> rel_tforms;
81 for (
size_t i = 0; i < kNumTforms; ++i) {
82 Eigen::Vector4d rel_qvec;
83 Eigen::Vector3d rel_tvec;
85 orig_tforms[kRefTform].Translation(),
86 orig_tforms[i].Rotation(),
87 orig_tforms[i].Translation(), &rel_qvec, &rel_tvec);
92 std::vector<GP3PEstimator::X_t> points2D;
93 for (
size_t i = 0; i < points3D.size(); ++i) {
94 Eigen::Vector3d point3D_camera = points3D[i];
95 orig_tforms[i % kNumTforms].TransformPoint(&point3D_camera);
96 points2D.emplace_back();
97 points2D.back().rel_tform = rel_tforms[i % kNumTforms];
98 points2D.back().xy = point3D_camera.hnormalized();
104 const auto report = ransac.
Estimate(points2D, points3D);
106 BOOST_CHECK_EQUAL(report.success,
true);
109 const double matrix_diff =
110 (orig_tforms[kRefTform].Matrix().topLeftCorner<3, 4>() - report.model)
112 BOOST_CHECK(matrix_diff < 1
e-2);
115 std::vector<double> residuals;
116 ransac.
estimator.Residuals(points2D, points3D, report.model, &residuals);
117 for (
size_t i = 0; i < residuals.size(); ++i) {
118 BOOST_CHECK(residuals[i] < 1
e-10);
122 ransac.
estimator.Residuals(points2D, points3D_faulty, report.model,
124 for (
size_t i = 0; i < residuals.size(); ++i) {
125 BOOST_CHECK(residuals[i] > 1
e-10);
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)