Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/test/test_homography_decomp.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// This is a test file for the function decomposeHomography contributed to OpenCV
4
// by Samson Yilma.
5
//
6
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
7
//
8
// By downloading, copying, installing or using the software you agree to this license.
9
// If you do not agree to this license, do not download, install,
10
// copy or use the software.
11
//
12
//
13
// License Agreement
14
// For Open Source Computer Vision Library
15
//
16
// Copyright (C) 2014, Samson Yilma ([email protected]), all rights reserved.
17
//
18
// Third party copyrights are property of their respective owners.
19
//
20
// Redistribution and use in source and binary forms, with or without modification,
21
// are permitted provided that the following conditions are met:
22
//
23
// * Redistribution's of source code must retain the above copyright notice,
24
// this list of conditions and the following disclaimer.
25
//
26
// * Redistribution's in binary form must reproduce the above copyright notice,
27
// this list of conditions and the following disclaimer in the documentation
28
// and/or other materials provided with the distribution.
29
//
30
// * The name of the copyright holders may not be used to endorse or promote products
31
// derived from this software without specific prior written permission.
32
//
33
// This software is provided by the copyright holders and contributors "as is" and
34
// any express or implied warranties, including, but not limited to, the implied
35
// warranties of merchantability and fitness for a particular purpose are disclaimed.
36
// In no event shall the Intel Corporation or contributors be liable for any direct,
37
// indirect, incidental, special, exemplary, or consequential damages
38
// (including, but not limited to, procurement of substitute goods or services;
39
// loss of use, data, or profits; or business interruption) however caused
40
// and on any theory of liability, whether in contract, strict liability,
41
// or tort (including negligence or otherwise) arising in any way out of
42
// the use of this software, even if advised of the possibility of such damage.
43
//
44
//M*/
45
46
#include "test_precomp.hpp"
47
48
namespace opencv_test { namespace {
49
50
class CV_HomographyDecompTest: public cvtest::BaseTest {
51
52
public:
53
CV_HomographyDecompTest()
54
{
55
buildTestDataSet();
56
}
57
58
protected:
59
void run(int)
60
{
61
vector<Mat> rotations;
62
vector<Mat> translations;
63
vector<Mat> normals;
64
65
decomposeHomographyMat(_H, _K, rotations, translations, normals);
66
67
//there should be at least 1 solution
68
ASSERT_GT(static_cast<int>(rotations.size()), 0);
69
ASSERT_GT(static_cast<int>(translations.size()), 0);
70
ASSERT_GT(static_cast<int>(normals.size()), 0);
71
72
ASSERT_EQ(rotations.size(), normals.size());
73
ASSERT_EQ(translations.size(), normals.size());
74
75
ASSERT_TRUE(containsValidMotion(rotations, translations, normals));
76
77
decomposeHomographyMat(_H, _K, rotations, noArray(), noArray());
78
ASSERT_GT(static_cast<int>(rotations.size()), 0);
79
}
80
81
private:
82
83
void buildTestDataSet()
84
{
85
_K = Matx33d(640, 0.0, 320,
86
0, 640, 240,
87
0, 0, 1);
88
89
_H = Matx33d(2.649157564634028, 4.583875997496426, 70.694447785121326,
90
-1.072756858861583, 3.533262150437228, 1513.656999614321649,
91
0.001303887589576, 0.003042206876298, 1.000000000000000
92
);
93
94
//expected solution for the given homography and intrinsic matrices
95
_R = Matx33d(0.43307983549125, 0.545749113549648, -0.717356090899523,
96
-0.85630229674426, 0.497582023798831, -0.138414255706431,
97
0.281404038139784, 0.67421809131173, 0.682818960388909);
98
99
_t = Vec3d(1.826751712278038, 1.264718492450820, 0.195080809998819);
100
_n = Vec3d(0.244875830334816, 0.480857890778889, 0.841909446789566);
101
}
102
103
bool containsValidMotion(std::vector<Mat>& rotations,
104
std::vector<Mat>& translations,
105
std::vector<Mat>& normals
106
)
107
{
108
double max_error = 1.0e-3;
109
110
vector<Mat>::iterator riter = rotations.begin();
111
vector<Mat>::iterator titer = translations.begin();
112
vector<Mat>::iterator niter = normals.begin();
113
114
for (;
115
riter != rotations.end() && titer != translations.end() && niter != normals.end();
116
++riter, ++titer, ++niter) {
117
118
double rdist = cvtest::norm(*riter, _R, NORM_INF);
119
double tdist = cvtest::norm(*titer, _t, NORM_INF);
120
double ndist = cvtest::norm(*niter, _n, NORM_INF);
121
122
if ( rdist < max_error
123
&& tdist < max_error
124
&& ndist < max_error )
125
return true;
126
}
127
128
return false;
129
}
130
131
Matx33d _R, _K, _H;
132
Vec3d _t, _n;
133
};
134
135
TEST(Calib3d_DecomposeHomography, regression) { CV_HomographyDecompTest test; test.safe_run(); }
136
137
}} // namespace
138
139