Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/perf/perf_affine2d.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// By downloading, copying, installing or using the software you agree to this license.
4
// If you do not agree to this license, do not download, install,
5
// copy or use the software.
6
//
7
//
8
// License Agreement
9
// For Open Source Computer Vision Library
10
// (3-clause BSD License)
11
//
12
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
13
// Third party copyrights are property of their respective owners.
14
//
15
// Redistribution and use in source and binary forms, with or without modification,
16
// are permitted provided that the following conditions are met:
17
//
18
// * Redistributions of source code must retain the above copyright notice,
19
// this list of conditions and the following disclaimer.
20
//
21
// * Redistributions in binary form must reproduce the above copyright notice,
22
// this list of conditions and the following disclaimer in the documentation
23
// and/or other materials provided with the distribution.
24
//
25
// * Neither the names of the copyright holders nor the names of the contributors
26
// may be used to endorse or promote products derived from this software
27
// without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall copyright holders or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "perf_precomp.hpp"
43
#include <algorithm>
44
#include <functional>
45
46
namespace opencv_test
47
{
48
using namespace perf;
49
50
CV_ENUM(Method, RANSAC, LMEDS)
51
typedef tuple<int, double, Method, size_t> AffineParams;
52
typedef TestBaseWithParam<AffineParams> EstimateAffine;
53
#define ESTIMATE_PARAMS Combine(Values(100000, 5000, 100), Values(0.99, 0.95, 0.9), Method::all(), Values(10, 0))
54
55
static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); }
56
57
static Mat rngPartialAffMat() {
58
double theta = rngIn(0, (float)CV_PI*2.f);
59
double scale = rngIn(0, 3);
60
double tx = rngIn(-2, 2);
61
double ty = rngIn(-2, 2);
62
double aff[2*3] = { std::cos(theta) * scale, -std::sin(theta) * scale, tx,
63
std::sin(theta) * scale, std::cos(theta) * scale, ty };
64
return Mat(2, 3, CV_64F, aff).clone();
65
}
66
67
PERF_TEST_P( EstimateAffine, EstimateAffine2D, ESTIMATE_PARAMS )
68
{
69
AffineParams params = GetParam();
70
const int n = get<0>(params);
71
const double confidence = get<1>(params);
72
const int method = get<2>(params);
73
const size_t refining = get<3>(params);
74
75
Mat aff(2, 3, CV_64F);
76
cv::randu(aff, -2., 2.);
77
78
// LMEDS can't handle more than 50% outliers (by design)
79
int m;
80
if (method == LMEDS)
81
m = 3*n/5;
82
else
83
m = 2*n/5;
84
const float shift_outl = 15.f;
85
const float noise_level = 20.f;
86
87
Mat fpts(1, n, CV_32FC2);
88
Mat tpts(1, n, CV_32FC2);
89
90
randu(fpts, 0., 100.);
91
transform(fpts, tpts, aff);
92
93
/* adding noise to some points */
94
Mat outliers = tpts.colRange(m, n);
95
outliers.reshape(1) += shift_outl;
96
97
Mat noise (outliers.size(), outliers.type());
98
randu(noise, 0., noise_level);
99
outliers += noise;
100
101
Mat aff_est;
102
vector<uchar> inliers (n);
103
104
warmup(inliers, WARMUP_WRITE);
105
warmup(fpts, WARMUP_READ);
106
warmup(tpts, WARMUP_READ);
107
108
TEST_CYCLE()
109
{
110
aff_est = estimateAffine2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
111
}
112
113
// we already have accuracy tests
114
SANITY_CHECK_NOTHING();
115
}
116
117
PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS )
118
{
119
AffineParams params = GetParam();
120
const int n = get<0>(params);
121
const double confidence = get<1>(params);
122
const int method = get<2>(params);
123
const size_t refining = get<3>(params);
124
125
Mat aff = rngPartialAffMat();
126
127
int m;
128
// LMEDS can't handle more than 50% outliers (by design)
129
if (method == LMEDS)
130
m = 3*n/5;
131
else
132
m = 2*n/5;
133
const float shift_outl = 15.f; const float noise_level = 20.f;
134
135
Mat fpts(1, n, CV_32FC2);
136
Mat tpts(1, n, CV_32FC2);
137
138
randu(fpts, 0., 100.);
139
transform(fpts, tpts, aff);
140
141
/* adding noise*/
142
Mat outliers = tpts.colRange(m, n);
143
outliers.reshape(1) += shift_outl;
144
145
Mat noise (outliers.size(), outliers.type());
146
randu(noise, 0., noise_level);
147
outliers += noise;
148
149
Mat aff_est;
150
vector<uchar> inliers (n);
151
152
warmup(inliers, WARMUP_WRITE);
153
warmup(fpts, WARMUP_READ);
154
warmup(tpts, WARMUP_READ);
155
156
TEST_CYCLE()
157
{
158
aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
159
}
160
161
// we already have accuracy tests
162
SANITY_CHECK_NOTHING();
163
}
164
165
} // namespace opencv_test
166
167