test_reprojection.cpp
4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#include "opencv2/stitching/warpers.hpp"
namespace opencv_test { namespace {
class ReprojectionTest : public ::testing::Test {
protected:
const size_t TEST_COUNT = 15;
Mat K, R;
RNG rng = RNG(0);
ReprojectionTest()
{
K = Mat::eye(3, 3, CV_32FC1);
float angle = (float)(30.0 * CV_PI / 180.0);
float rotationMatrix[9] = {
(float)cos(angle), (float)sin(angle), 0,
(float)-sin(angle), (float)cos(angle), 0,
0, 0, 1
};
Mat(3, 3, CV_32FC1, rotationMatrix).copyTo(R);
}
void TestReprojection(Ptr<detail::RotationWarper> warper, Point2f pt) {
Point2f projected_pt = warper->warpPoint(pt, K, R);
Point2f reprojected_pt = warper->warpPointBackward(projected_pt, K, R);
EXPECT_NEAR(pt.x, reprojected_pt.x, float( 1e-5));
EXPECT_NEAR(pt.y, reprojected_pt.y, float( 1e-5));
}
};
TEST_F(ReprojectionTest, PlaneWarper)
{
Ptr<WarperCreator> creator = makePtr<PlaneWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, AffineWarper)
{
Ptr<WarperCreator> creator = makePtr<AffineWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, CylindricalWarper)
{
Ptr<WarperCreator> creator = makePtr<CylindricalWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, SphericalWarper)
{
Ptr<WarperCreator> creator = makePtr<SphericalWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, FisheyeWarper)
{
Ptr<WarperCreator> creator = makePtr<FisheyeWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, StereographicWarper)
{
Ptr<WarperCreator> creator = makePtr<StereographicWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, CompressedRectilinearWarper)
{
Ptr<WarperCreator> creator = makePtr<CompressedRectilinearWarper>(1.5f, 1.0f);
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, CompressedRectilinearPortraitWarper)
{
Ptr<WarperCreator> creator = makePtr<CompressedRectilinearPortraitWarper>(1.5f, 1.0f);
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, PaniniWarper)
{
Ptr<WarperCreator> creator = makePtr<PaniniWarper>(1.5f, 1.0f);
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, PaniniPortraitWarper)
{
Ptr<WarperCreator> creator = makePtr<PaniniPortraitWarper>(1.5f, 1.0f);
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, MercatorWarper)
{
Ptr<WarperCreator> creator = makePtr<MercatorWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
TEST_F(ReprojectionTest, TransverseMercatorWarper)
{
Ptr<WarperCreator> creator = makePtr<TransverseMercatorWarper>();
for (size_t i = 0; i < TEST_COUNT; ++i) {
TestReprojection(creator->create(1), Point2f(rng.uniform(-1.f, 1.f), rng.uniform(-1.f, 1.f)));
}
}
}} // namespace