Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/perf/perf_stereosgbm.cpp
16337 views
1
/*
2
* By downloading, copying, installing or using the software you agree to this license.
3
* If you do not agree to this license, do not download, install,
4
* copy or use the software.
5
*
6
*
7
* License Agreement
8
* For Open Source Computer Vision Library
9
* (3 - clause BSD License)
10
*
11
* Redistribution and use in source and binary forms, with or without modification,
12
* are permitted provided that the following conditions are met :
13
*
14
* * Redistributions of source code must retain the above copyright notice,
15
* this list of conditions and the following disclaimer.
16
*
17
* * Redistributions in binary form must reproduce the above copyright notice,
18
* this list of conditions and the following disclaimer in the documentation
19
* and / or other materials provided with the distribution.
20
*
21
* * Neither the names of the copyright holders nor the names of the contributors
22
* may be used to endorse or promote products derived from this software
23
* without specific prior written permission.
24
*
25
* This software is provided by the copyright holders and contributors "as is" and
26
* any express or implied warranties, including, but not limited to, the implied
27
* warranties of merchantability and fitness for a particular purpose are disclaimed.
28
* In no event shall copyright holders or contributors be liable for any direct,
29
* indirect, incidental, special, exemplary, or consequential damages
30
* (including, but not limited to, procurement of substitute goods or services;
31
* loss of use, data, or profits; or business interruption) however caused
32
* and on any theory of liability, whether in contract, strict liability,
33
* or tort(including negligence or otherwise) arising in any way out of
34
* the use of this software, even if advised of the possibility of such damage.
35
*/
36
37
#include "perf_precomp.hpp"
38
39
namespace opencv_test
40
{
41
using namespace perf;
42
using namespace testing;
43
44
static void MakeArtificialExample(RNG rng, Mat& dst_left_view, Mat& dst_view);
45
46
CV_ENUM(SGBMModes, StereoSGBM::MODE_SGBM, StereoSGBM::MODE_SGBM_3WAY, StereoSGBM::MODE_HH4);
47
typedef tuple<Size, int, SGBMModes> SGBMParams;
48
typedef TestBaseWithParam<SGBMParams> TestStereoCorresp;
49
50
#ifndef _DEBUG
51
PERF_TEST_P( TestStereoCorresp, SGBM, Combine(Values(Size(1280,720),Size(640,480)), Values(256,128), SGBMModes::all()) )
52
#else
53
PERF_TEST_P( TestStereoCorresp, DISABLED_TooLongInDebug_SGBM, Combine(Values(Size(1280,720),Size(640,480)), Values(256,128), SGBMModes::all()) )
54
#endif
55
{
56
RNG rng(0);
57
58
SGBMParams params = GetParam();
59
60
Size sz = get<0>(params);
61
int num_disparities = get<1>(params);
62
int mode = get<2>(params);
63
64
Mat src_left(sz, CV_8UC3);
65
Mat src_right(sz, CV_8UC3);
66
Mat dst(sz, CV_16S);
67
68
MakeArtificialExample(rng,src_left,src_right);
69
70
int wsize = 3;
71
int P1 = 8*src_left.channels()*wsize*wsize;
72
TEST_CYCLE()
73
{
74
Ptr<StereoSGBM> sgbm = StereoSGBM::create(0,num_disparities,wsize,P1,4*P1,1,63,25,0,0,mode);
75
sgbm->compute(src_left,src_right,dst);
76
}
77
78
SANITY_CHECK(dst, .01, ERROR_RELATIVE);
79
}
80
81
void MakeArtificialExample(RNG rng, Mat& dst_left_view, Mat& dst_right_view)
82
{
83
int w = dst_left_view.cols;
84
int h = dst_left_view.rows;
85
86
//params:
87
unsigned char bg_level = (unsigned char)rng.uniform(0.0,255.0);
88
unsigned char fg_level = (unsigned char)rng.uniform(0.0,255.0);
89
int rect_width = (int)rng.uniform(w/16,w/2);
90
int rect_height = (int)rng.uniform(h/16,h/2);
91
int rect_disparity = (int)(0.15*w);
92
double sigma = 3.0;
93
94
int rect_x_offset = (w-rect_width) /2;
95
int rect_y_offset = (h-rect_height)/2;
96
97
if(dst_left_view.channels()==3)
98
{
99
dst_left_view = Scalar(Vec3b(bg_level,bg_level,bg_level));
100
dst_right_view = Scalar(Vec3b(bg_level,bg_level,bg_level));
101
}
102
else
103
{
104
dst_left_view = Scalar(bg_level);
105
dst_right_view = Scalar(bg_level);
106
}
107
108
Mat dst_left_view_rect = Mat(dst_left_view, Rect(rect_x_offset,rect_y_offset,rect_width,rect_height));
109
if(dst_left_view.channels()==3)
110
dst_left_view_rect = Scalar(Vec3b(fg_level,fg_level,fg_level));
111
else
112
dst_left_view_rect = Scalar(fg_level);
113
114
rect_x_offset-=rect_disparity;
115
116
Mat dst_right_view_rect = Mat(dst_right_view, Rect(rect_x_offset,rect_y_offset,rect_width,rect_height));
117
if(dst_right_view.channels()==3)
118
dst_right_view_rect = Scalar(Vec3b(fg_level,fg_level,fg_level));
119
else
120
dst_right_view_rect = Scalar(fg_level);
121
122
//add some gaussian noise:
123
unsigned char *l, *r;
124
for(int i=0;i<h;i++)
125
{
126
l = dst_left_view.ptr(i);
127
r = dst_right_view.ptr(i);
128
129
if(dst_left_view.channels()==3)
130
{
131
for(int j=0;j<w;j++)
132
{
133
l[0] = saturate_cast<unsigned char>(l[0] + rng.gaussian(sigma));
134
l[1] = saturate_cast<unsigned char>(l[1] + rng.gaussian(sigma));
135
l[2] = saturate_cast<unsigned char>(l[2] + rng.gaussian(sigma));
136
l+=3;
137
138
r[0] = saturate_cast<unsigned char>(r[0] + rng.gaussian(sigma));
139
r[1] = saturate_cast<unsigned char>(r[1] + rng.gaussian(sigma));
140
r[2] = saturate_cast<unsigned char>(r[2] + rng.gaussian(sigma));
141
r+=3;
142
}
143
}
144
else
145
{
146
for(int j=0;j<w;j++)
147
{
148
l[0] = saturate_cast<unsigned char>(l[0] + rng.gaussian(sigma));
149
l++;
150
151
r[0] = saturate_cast<unsigned char>(r[0] + rng.gaussian(sigma));
152
r++;
153
}
154
}
155
}
156
}
157
158
}
159
160