-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstereomatchingsgbm.cpp
139 lines (100 loc) · 3.36 KB
/
stereomatchingsgbm.cpp
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
132
133
134
135
136
137
138
139
#include "stereomatchingsgbm.hpp"
using namespace std;
using namespace cv;
StereoMatchingSGBM::StereoMatchingSGBM(): StereoMatching("Semi-Global Block Matching"),
I_minDisparity(0),
I_numberOfDisparities(1),
I_SADWindowSize(2),
I_preFilterCap(3),
I_uniquenessRatio(4),
I_speckleWindowSize(5),
I_speckleRange(6),
I_disp12MaxDiff(7),
I_fullDP(8){
init();
}
StereoMatchingSGBM::~StereoMatchingSGBM(){
}
void StereoMatchingSGBM::init(){
//0
Property * prop = new Property("Minimum disparity", 0, Property::INT);
prop->minValue = -50;
prop->maxValue = 50;
prop->step = 5;
properties.push_back(prop);
//1
prop = new Property("Number of disparities", 2, Property::DISCRETE);
int max = 4;
int * values = new int[max];
for(int i = 0; i < max; ++i)
values[i] = 16*i;
prop->minValue = 0;
prop->maxValue = max;
prop->tableValues = values;
properties.push_back(prop);
//2
prop = new Property("SAD window size", 5, Property::DISCRETE);
max = 8;
int defValues[8] = {1, 3, 5, 7, 9, 11, 21, 31};
int * values2 = new int[max];
for(int i = 0; i < max; ++i)
values2[i] = defValues[i];
prop->minValue = 0;
prop->maxValue = max;
prop->tableValues = values2;
properties.push_back(prop);
//3
prop = new Property("PrefilterCap", 31, Property::INT);
prop->minValue = 0;
prop->maxValue = 50;
properties.push_back(prop);
//4
prop = new Property("UniquenessRatio", 1, Property::INT);
prop->minValue = 0;
prop->maxValue = 35;
properties.push_back(prop);
//5
prop = new Property("Speckle window size", 400, Property::INT);
prop->minValue = 0;
prop->maxValue = 500;
prop->step = 50;
properties.push_back(prop);
//6
prop = new Property("Speckle range", 1, Property::DISCRETE);
max = 4;
int * values3 = new int[max];
for(int i = 0; i < max; ++i)
values3[i] = 16*i;
prop->minValue = 0;
prop->maxValue = max;
prop->tableValues = values;
properties.push_back(prop);
//7
prop = new Property("Disparity max difference", 2, Property::INT);
prop->minValue = -1;
prop->maxValue = 20;
properties.push_back(prop);
//8
prop = new Property("Use full DP", 0, Property::BOOL);
properties.push_back(prop);
applyAllParametres();
}
void StereoMatchingSGBM::applyAllParametres(){
changeProperties();
sgbm.preFilterCap = properties[I_preFilterCap]->getValue();
sgbm.SADWindowSize = properties[I_SADWindowSize]->tableValues[properties[I_SADWindowSize]->getValue()];
sgbm.P1 = 16*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.P2 = 64*sgbm.SADWindowSize*sgbm.SADWindowSize;
sgbm.minDisparity = properties[I_minDisparity]->getValue();
sgbm.numberOfDisparities = properties[I_numberOfDisparities]->tableValues[properties[I_numberOfDisparities]->getValue()];
sgbm.uniquenessRatio = properties[I_uniquenessRatio]->getValue();
sgbm.speckleWindowSize = properties[I_speckleWindowSize]->getValue();
sgbm.speckleRange = properties[I_speckleRange]->tableValues[properties[I_speckleRange]->getValue()];
sgbm.disp12MaxDiff = properties[I_disp12MaxDiff]->getValue();
sgbm.fullDP = (bool)properties[I_fullDP]->getValue();
}
void StereoMatchingSGBM::exec(Mat & image1, Mat & image2, Mat & retImage){
Mat disp;
sgbm(image1, image2, disp);
disp.convertTo(retImage, CV_8U, 255/(sgbm.numberOfDisparities*16.));
}