32 #define TEST_NAME "base/projection"
47 const Eigen::Vector3d tvec = Eigen::Vector3d::Random();
52 BOOST_CHECK((proj_matrix1 - proj_matrix2).norm() < 1
e-6);
53 BOOST_CHECK((proj_matrix1.leftCols<3>() - R).norm() < 1
e-6);
54 BOOST_CHECK_CLOSE((proj_matrix1.rightCols<1>() - tvec).norm(), 0, 1
e-6);
55 BOOST_CHECK_CLOSE((proj_matrix2.leftCols<3>() - R).norm(), 0, 1
e-6);
56 BOOST_CHECK_CLOSE((proj_matrix2.rightCols<1>() - tvec).norm(), 0, 1
e-6);
61 const Eigen::Vector3d tvec = Eigen::Vector3d::Random();
67 BOOST_CHECK((proj_matrix - inv_inv_proj_matrix).norm() < 1
e-6);
71 const Eigen::Matrix3d A = Eigen::Matrix3d::Identity();
77 for (
int i = 1; i < 100; ++i) {
78 Eigen::Matrix3d ref_K = i * Eigen::Matrix3d::Identity();
82 const Eigen::Vector3d ref_T = Eigen::Vector3d::Random();
89 BOOST_CHECK(ref_K.isApprox(K, 1
e-6));
90 BOOST_CHECK(ref_R.isApprox(R, 1
e-6));
91 BOOST_CHECK(ref_T.isApprox(T, 1
e-6));
97 const Eigen::Vector3d tvec = Eigen::Vector3d::Zero();
101 const Eigen::Vector3d point3D = Eigen::Vector3d::Random().cwiseAbs();
102 const Eigen::Vector3d point2D_h = proj_matrix * point3D.homogeneous();
103 const Eigen::Vector2d point2D = point2D_h.hnormalized();
108 const double error1 =
110 BOOST_CHECK_EQUAL(error1, 0);
112 const double error2 =
114 BOOST_CHECK_GE(error2, 0);
115 BOOST_CHECK_LT(error2, 1
e-6);
118 point2D.array() + 1, point3D, qvec, tvec, camera);
119 BOOST_CHECK_CLOSE(error3, 2, 1
e-6);
122 point2D.array() + 1, point3D, proj_matrix, camera);
123 BOOST_CHECK_CLOSE(error4, 2, 1
e-6);
128 const Eigen::Vector3d tvec = Eigen::Vector3d(0, 0, 0);
133 camera.
Params() = {1, 0, 0};
136 Eigen::Vector2d(0, 0), Eigen::Vector3d(0, 0, 1), proj_matrix, camera);
137 BOOST_CHECK_CLOSE(error1, 0, 1
e-6);
140 Eigen::Vector2d(0, 0), Eigen::Vector3d(0, 1, 1), proj_matrix, camera);
141 BOOST_CHECK_CLOSE(error2,
M_PI / 4, 1
e-6);
144 Eigen::Vector2d(0, 0), Eigen::Vector3d(0, 5, 5), proj_matrix, camera);
145 BOOST_CHECK_CLOSE(error3,
M_PI / 4, 1
e-6);
148 Eigen::Vector2d(1, 0), Eigen::Vector3d(0, 0, 1), proj_matrix, camera);
149 BOOST_CHECK_CLOSE(error4,
M_PI / 4, 1
e-6);
152 Eigen::Vector2d(2, 0), Eigen::Vector3d(0, 0, 1), proj_matrix, camera);
153 BOOST_CHECK_CLOSE(error5, 1.10714872, 1
e-6);
156 Eigen::Vector2d(2, 0), Eigen::Vector3d(1, 0, 1), proj_matrix, camera);
157 BOOST_CHECK_CLOSE(error6, 1.10714872 -
M_PI / 4, 1
e-6);
160 Eigen::Vector2d(2, 0), Eigen::Vector3d(5, 0, 5), proj_matrix, camera);
161 BOOST_CHECK_CLOSE(error7, 1.10714872 -
M_PI / 4, 1
e-6);
164 Eigen::Vector2d(1, 0), Eigen::Vector3d(-1, 0, 1), proj_matrix, camera);
165 BOOST_CHECK_CLOSE(error8,
M_PI / 2, 1
e-6);
168 Eigen::Vector2d(1, 0), Eigen::Vector3d(-1, 0, 0), proj_matrix, camera);
169 BOOST_CHECK_CLOSE(error9,
M_PI * 3 / 4, 1
e-6);
172 Eigen::Vector2d(1, 0), Eigen::Vector3d(-1, 0, -1), proj_matrix, camera);
173 BOOST_CHECK_CLOSE(error10,
M_PI, 1
e-6);
176 Eigen::Vector2d(1, 0), Eigen::Vector3d(0, 0, -1), proj_matrix, camera);
177 BOOST_CHECK_CLOSE(error11,
M_PI * 3 / 4, 1
e-6);
181 const Eigen::Vector4d qvec(1, 0, 0, 0);
182 const Eigen::Vector3d tvec(0, 0, 0);
186 const double depth1 =
CalculateDepth(proj_matrix, Eigen::Vector3d(0, 0, 0));
187 BOOST_CHECK_CLOSE(depth1, 0, 1
e-10);
188 const double depth2 =
CalculateDepth(proj_matrix, Eigen::Vector3d(0, 2, 0));
189 BOOST_CHECK_CLOSE(depth2, 0, 1
e-10);
192 const double depth3 =
CalculateDepth(proj_matrix, Eigen::Vector3d(0, 0, 1));
193 BOOST_CHECK_CLOSE(depth3, 1, 1
e-10);
196 const double depth4 =
CalculateDepth(proj_matrix, Eigen::Vector3d(0, 0, -1));
197 BOOST_CHECK_CLOSE(depth4, -1, 1
e-10);
201 const Eigen::Vector4d qvec(1, 0, 0, 0);
202 const Eigen::Vector3d tvec(0, 0, 0);
208 BOOST_CHECK(!check1);
211 BOOST_CHECK(!check2);
221 BOOST_CHECK(!check4);
void InitializeWithId(const int model_id, const double focal_length, const size_t width, const size_t height)
const std::vector< double > & Params() const
void SetModelId(const int model_id)
Matrix< double, 3, 4 > Matrix3x4d
double CalculateSquaredReprojectionError(const Eigen::Vector2d &point2D, const Eigen::Vector3d &point3D, const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, const Camera &camera)
bool HasPointPositiveDepth(const Eigen::Matrix3x4d &proj_matrix, const Eigen::Vector3d &point3D)
Eigen::Matrix3d EulerAnglesToRotationMatrix(const double rx, const double ry, const double rz)
Eigen::Vector4d ComposeIdentityQuaternion()
Eigen::Matrix3x4d InvertProjectionMatrix(const Eigen::Matrix3x4d &proj_matrix)
double CalculateDepth(const Eigen::Matrix3x4d &proj_matrix, const Eigen::Vector3d &point3D)
Eigen::Vector4d RotationMatrixToQuaternion(const Eigen::Matrix3d &rot_mat)
bool DecomposeProjectionMatrix(const Eigen::Matrix3x4d &P, Eigen::Matrix3d *K, Eigen::Matrix3d *R, Eigen::Vector3d *T)
Eigen::Matrix3d ComputeClosestRotationMatrix(const Eigen::Matrix3d &matrix)
Eigen::Matrix3x4d ComposeProjectionMatrix(const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec)
double CalculateAngularError(const Eigen::Vector2d &point2D, const Eigen::Vector3d &point3D, const Eigen::Vector4d &qvec, const Eigen::Vector3d &tvec, const Camera &camera)
BOOST_AUTO_TEST_CASE(TestComposeProjectionMatrix)
static const int model_id