24#include "testing/testing.h"
37void CheckHomography2DTransform(
const Mat3&
H,
const Mat& x1,
const Mat& x2) {
38 for (
int i = 0; i < x2.cols(); ++i) {
39 Vec3 x2_expected = x2.col(i);
40 Vec3 x2_observed =
H * x1.col(i);
41 x2_observed /= x2_observed(2);
42 EXPECT_MATRIX_NEAR(x2_expected, x2_observed, 1
e-8);
48TEST(Homography2DTest, Rotation45AndTranslationXY) {
59 m <<
cos(angle), -
sin(angle), -2,
66 for (
int i = 0; i < x2.cols(); ++i) {
67 x2.col(i) = m * x1.col(i);
72 VLOG(1) <<
"Mat Homography2D ";
73 VLOG(1) << homography_mat;
76 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
79TEST(Homography2DTest, AffineGeneral4) {
95 for (
int i = 0; i < x2.cols(); ++i) {
96 x2.col(i) = m * x1.col(i);
101 VLOG(1) <<
"Mat Homography2D";
102 VLOG(1) << homography_mat;
103 CheckHomography2DTransform(homography_mat, x1, x2);
109 homography_mat.setIdentity();
112 VLOG(1) <<
"Mat Homography2D ";
113 VLOG(1) << homography_mat;
114 CheckHomography2DTransform(homography_mat, x1, x2);
117TEST(Homography2DTest, AffineGeneral5) {
132 for (
int i = 0; i < x2.cols(); ++i) {
133 x2.col(i) = m * x1.col(i);
139 VLOG(1) <<
"Mat Homography2D ";
140 VLOG(1) << homography_mat;
141 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
147 homography_mat.setIdentity();
150 VLOG(1) <<
"Mat Homography2D ";
151 VLOG(1) << homography_mat;
152 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
155TEST(Homography2DTest, HomographyGeneral) {
170 for (
int i = 0; i < x2.cols(); ++i) {
171 x2.col(i) = m * x1.col(i);
177 VLOG(1) <<
"Mat Homography2D ";
178 VLOG(1) << homography_mat;
179 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
182TEST(Homography3DTest, RotationAndTranslationXYZ) {
202 0,
cos(angle), -
sin(angle), 3,
203 0,
sin(angle),
cos(angle), -2,
212 -
sin(angle), 0,
cos(angle), 0,
220 sin(angle),
cos(angle), 0, 0,
226 for (
int i = 0; i < x2.cols(); ++i) {
227 x2.col(i) =
M * x1.col(i);
233 VLOG(1) <<
"Mat Homography3D " << homography_mat;
234 VLOG(1) <<
"Mat GT " <<
M;
235 EXPECT_MATRIX_NEAR(homography_mat,
M, 1
e-8);
238TEST(Homography3DTest, AffineGeneral) {
255 for (
int i = 0; i < x2.cols(); ++i) {
256 x2.col(i) = m * x1.col(i);
261 VLOG(1) <<
"Mat Homography3D ";
262 VLOG(1) << homography_mat;
263 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
266TEST(Homography3DTest, HomographyGeneral) {
283 for (
int i = 0; i < x2.cols(); ++i) {
284 x2.col(i) = m * x1.col(i);
289 VLOG(1) <<
"Mat Homography3D";
290 VLOG(1) << homography_mat;
291 EXPECT_MATRIX_NEAR(homography_mat, m, 1
e-8);
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ccl_device_inline float3 cos(float3 v)
T sin(const AngleRadianBase< T > &a)
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
void HomogeneousToEuclidean(const Mat &H, Mat *X)
bool Homography2DFromCorrespondencesLinear(const Mat &x1, const Mat &x2, Mat3 *H, double expected_precision)
bool Homography3DFromCorrespondencesLinear(const Mat &x1, const Mat &x2, Mat4 *H, double expected_precision)