Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/stitching/perf/perf_stich.cpp
16344 views
1
#include "perf_precomp.hpp"
2
#include "opencv2/imgcodecs.hpp"
3
#include "opencv2/opencv_modules.hpp"
4
5
#include "opencv2/core/ocl.hpp"
6
7
namespace opencv_test
8
{
9
using namespace perf;
10
11
#define SURF_MATCH_CONFIDENCE 0.65f
12
#define ORB_MATCH_CONFIDENCE 0.3f
13
#define WORK_MEGAPIX 0.6
14
15
typedef TestBaseWithParam<string> stitch;
16
typedef TestBaseWithParam<tuple<string, string> > stitchDatasets;
17
18
#ifdef HAVE_OPENCV_XFEATURES2D
19
#define TEST_DETECTORS testing::Values("surf", "orb", "akaze")
20
#else
21
#define TEST_DETECTORS testing::Values("orb", "akaze")
22
#endif
23
#define AFFINE_DATASETS testing::Values("s", "budapest", "newspaper", "prague")
24
25
PERF_TEST_P(stitch, a123, TEST_DETECTORS)
26
{
27
Mat pano;
28
29
vector<Mat> imgs;
30
imgs.push_back( imread( getDataPath("stitching/a1.png") ) );
31
imgs.push_back( imread( getDataPath("stitching/a2.png") ) );
32
imgs.push_back( imread( getDataPath("stitching/a3.png") ) );
33
34
Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());
35
36
Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
37
? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
38
: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
39
40
declare.time(30 * 20).iterations(20);
41
42
while(next())
43
{
44
Stitcher stitcher = Stitcher::createDefault();
45
stitcher.setFeaturesFinder(featuresFinder);
46
stitcher.setFeaturesMatcher(featuresMatcher);
47
stitcher.setWarper(makePtr<SphericalWarper>());
48
stitcher.setRegistrationResol(WORK_MEGAPIX);
49
50
startTimer();
51
stitcher.stitch(imgs, pano);
52
stopTimer();
53
}
54
55
EXPECT_NEAR(pano.size().width, 1182, 50);
56
EXPECT_NEAR(pano.size().height, 682, 30);
57
58
SANITY_CHECK_NOTHING();
59
}
60
61
PERF_TEST_P(stitch, b12, TEST_DETECTORS)
62
{
63
Mat pano;
64
65
vector<Mat> imgs;
66
imgs.push_back( imread( getDataPath("stitching/b1.png") ) );
67
imgs.push_back( imread( getDataPath("stitching/b2.png") ) );
68
69
Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(GetParam());
70
71
Ptr<detail::FeaturesMatcher> featuresMatcher = GetParam() == "orb"
72
? makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE)
73
: makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE);
74
75
declare.time(30 * 20).iterations(20);
76
77
while(next())
78
{
79
Stitcher stitcher = Stitcher::createDefault();
80
stitcher.setFeaturesFinder(featuresFinder);
81
stitcher.setFeaturesMatcher(featuresMatcher);
82
stitcher.setWarper(makePtr<SphericalWarper>());
83
stitcher.setRegistrationResol(WORK_MEGAPIX);
84
85
startTimer();
86
stitcher.stitch(imgs, pano);
87
stopTimer();
88
}
89
90
EXPECT_NEAR(pano.size().width, 1117, GetParam() == "surf" ? 100 : 50);
91
EXPECT_NEAR(pano.size().height, 642, GetParam() == "surf" ? 60 : 30);
92
93
SANITY_CHECK_NOTHING();
94
}
95
96
PERF_TEST_P(stitchDatasets, affine, testing::Combine(AFFINE_DATASETS, TEST_DETECTORS))
97
{
98
string dataset = get<0>(GetParam());
99
string detector = get<1>(GetParam());
100
101
Mat pano;
102
vector<Mat> imgs;
103
int width, height, allowed_diff = 20;
104
Ptr<detail::FeaturesFinder> featuresFinder = getFeatureFinder(detector);
105
106
if(dataset == "budapest")
107
{
108
imgs.push_back(imread(getDataPath("stitching/budapest1.jpg")));
109
imgs.push_back(imread(getDataPath("stitching/budapest2.jpg")));
110
imgs.push_back(imread(getDataPath("stitching/budapest3.jpg")));
111
imgs.push_back(imread(getDataPath("stitching/budapest4.jpg")));
112
imgs.push_back(imread(getDataPath("stitching/budapest5.jpg")));
113
imgs.push_back(imread(getDataPath("stitching/budapest6.jpg")));
114
width = 2313;
115
height = 1158;
116
// this dataset is big, the results between surf and orb differ slightly,
117
// but both are still good
118
allowed_diff = 50;
119
}
120
else if (dataset == "newspaper")
121
{
122
imgs.push_back(imread(getDataPath("stitching/newspaper1.jpg")));
123
imgs.push_back(imread(getDataPath("stitching/newspaper2.jpg")));
124
imgs.push_back(imread(getDataPath("stitching/newspaper3.jpg")));
125
imgs.push_back(imread(getDataPath("stitching/newspaper4.jpg")));
126
width = 1791;
127
height = 1136;
128
// we need to boost ORB number of features to be able to stitch this dataset
129
// SURF works just fine with default settings
130
if(detector == "orb")
131
featuresFinder = makePtr<detail::OrbFeaturesFinder>(Size(3,1), 3000);
132
}
133
else if (dataset == "prague")
134
{
135
imgs.push_back(imread(getDataPath("stitching/prague1.jpg")));
136
imgs.push_back(imread(getDataPath("stitching/prague2.jpg")));
137
width = 983;
138
height = 1759;
139
}
140
else // dataset == "s"
141
{
142
imgs.push_back(imread(getDataPath("stitching/s1.jpg")));
143
imgs.push_back(imread(getDataPath("stitching/s2.jpg")));
144
width = 1815;
145
height = 700;
146
}
147
148
declare.time(30 * 20).iterations(20);
149
150
while(next())
151
{
152
Ptr<Stitcher> stitcher = Stitcher::create(Stitcher::SCANS, false);
153
stitcher->setFeaturesFinder(featuresFinder);
154
155
if (cv::ocl::useOpenCL())
156
cv::theRNG() = cv::RNG(12345); // prevent fails of Windows OpenCL builds (see #8294)
157
158
startTimer();
159
stitcher->stitch(imgs, pano);
160
stopTimer();
161
}
162
163
EXPECT_NEAR(pano.size().width, width, allowed_diff);
164
EXPECT_NEAR(pano.size().height, height, allowed_diff);
165
166
SANITY_CHECK_NOTHING();
167
}
168
169
} // namespace
170
171