1 | |
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 | #include "opencv2/calib3d.hpp"
|
48 | #include <vector>
|
49 |
|
50 | using namespace cv;
|
51 | using namespace std;
|
52 |
|
53 | class CV_HomographyDecompTest: public cvtest::BaseTest {
|
54 |
|
55 | public:
|
56 | CV_HomographyDecompTest()
|
57 | {
|
58 | buildTestDataSet();
|
59 | }
|
60 |
|
61 | protected:
|
62 | void run(int)
|
63 | {
|
64 | vector<Mat> rotations;
|
65 | vector<Mat> translations;
|
66 | vector<Mat> normals;
|
67 |
|
68 | decomposeHomographyMat(_H, _K, rotations, translations, normals);
|
69 |
|
70 |
|
71 | ASSERT_GT(static_cast<int>(rotations.size()), 0);
|
72 | ASSERT_GT(static_cast<int>(translations.size()), 0);
|
73 | ASSERT_GT(static_cast<int>(normals.size()), 0);
|
74 |
|
75 | ASSERT_EQ(rotations.size(), normals.size());
|
76 | ASSERT_EQ(translations.size(), normals.size());
|
77 |
|
78 | ASSERT_TRUE(containsValidMotion(rotations, translations, normals));
|
79 |
|
80 | decomposeHomographyMat(_H, _K, rotations, noArray(), noArray());
|
81 | ASSERT_GT(static_cast<int>(rotations.size()), 0);
|
82 | }
|
83 |
|
84 | private:
|
85 |
|
86 | void buildTestDataSet()
|
87 | {
|
88 | _K = Matx33d(1.0, 0.0, 0.0,
|
89 | 0.0, 1.0, 0.0,
|
90 | 0.0, 0.0, 1.0);
|
91 |
|
92 | _H = Matx33d(-16.9507, -0.221925, -14.9252,
|
93 | -4.29529, -14.8487, -10.1566,
|
94 | 4.06517, -11.1937, 1.0);
|
95 |
|
96 |
|
97 | _R = Matx33d(0.942846, -0.0248848, 0.332299,
|
98 | 0.242688, 0.734634, -0.633574,
|
99 | -0.228352, 0.678007, 0.698686);
|
100 |
|
101 | _t = Vec3d(0.330964, 0.798468, -0.502904);
|
102 | _n = Vec3d(-0.00350954, 0.0747496, 0.997196);
|
103 | }
|
104 |
|
105 | bool containsValidMotion(std::vector<Mat>& rotations,
|
106 | std::vector<Mat>& translations,
|
107 | std::vector<Mat>& normals
|
108 | )
|
109 | {
|
110 | double max_error = 1.0;
|
111 |
|
112 | vector<Mat>::iterator riter = rotations.begin();
|
113 | vector<Mat>::iterator titer = translations.begin();
|
114 | vector<Mat>::iterator niter = normals.begin();
|
115 |
|
116 | for (;
|
117 | riter != rotations.end() && titer != translations.end() && niter != normals.end();
|
118 | ++riter, ++titer, ++niter) {
|
119 |
|
120 | double rdist = norm(*riter, _R, NORM_INF);
|
121 | double tdist = norm(*titer, _t, NORM_INF);
|
122 | double ndist = norm(*niter, _n, NORM_INF);
|
123 |
|
124 | if ( rdist < max_error
|
125 | && tdist < max_error
|
126 | && ndist < max_error )
|
127 | return true;
|
128 | }
|
129 |
|
130 | return false;
|
131 | }
|
132 |
|
133 | Matx33d _R, _K, _H;
|
134 | Vec3d _t, _n;
|
135 | };
|
136 |
|
137 | TEST(Calib3d_DecomposeHomography, regression) { CV_HomographyDecompTest test; test.safe_run(); }
|